I have a simple context that contains 1 Table from a DB and 1 View from the same DB. The Table has a field, OrderNumber, that is the PK of the View. The View simply has details that I want to include and as such is a 1:1 with the table.
I am trying to do all of this through Code First and have my Models but I am struggling on how I link them in my Model and have it save just the PK of the View in the OrderNumber field.
Below is what I have so far:
public partial class MyTable
{
public int ID { get; set; }
[StringLength(10)]
public string OrderNumber{ get; set; }
[StringLength(50)]
public string Description { get; set; }
[StringLength(500)]
public string RequestorNote { get; set; }
[StringLength(500)]
public string WashNote { get; set; }
public StatusChoices Status { get; set; }
}
[Table("MyView")]
public partial class MyView
{
[Key]
[Column(Order = 1)]
[StringLength(20)]
public string No_ { get; set; }
[Column(Order = 2)]
[StringLength(50)]
public string Description { get; set; }
[Column("Routing No_", Order = 3)]
[StringLength(20)]
public string Routing_No_ { get; set; }
[Column("Starting Date-Time", Order = 4)]
public DateTime Starting_Date_Time { get; set; }
}
Assuming No_
in MyView
is the OrderNumber
from MyTable
why not add a navigation property?
public virtual MyView OrderDetails { get; set; }