所以我有一个模型:在MVC模型中,如何查找不同表中的字段?
[Table("Site")]
public class Store : MPropertyAsStringSettable {
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public string Name { get; set; }
public int CompanyID { get; set; }
public bool IsActive { get; set; }
public string Address { get; set; }
public string City { get; set; }
[Display(Name = "Province")]
public int ProvinceID { get; set; }
public string Postal { get; set; }
public string Phone { get; set; }
public int StoreNumber { get; set; }
public bool visible { get; set; }
public DateTime lastShift { get; set; }
}
领域lastShift是从一个叫“位移”不同的表,如何从该表得到它?
编辑:查找必须是这样的:
select top 1 shiftDate as lastShift from [Shifts] where SiteID = Store.ID
这是我如何加载我的数据:
public class MyDbContext: DbContext {
public MyDbContext()
: base("name=DefaultConnection") {
}
public DbSet<UserAccount> UserAccounts { get; set; }
public DbSet<Company> Companies { get; set; }
public DbSet<Store> Stores { get; set; }
public DbSet<ProvinceModel> Provinces { get; set; }
}
这是我如何使用它:
MyDbContext database = new MyDbContext();
var myStores = from database.Stores select ID;
仅供参考 - 这与MVC无关,这是实体框架。 – jrummell 2013-04-10 15:23:27
这个问题呢?你能看看吗?在此先感谢... http://stackoverflow.com/questions/29333787/how-to-create-lookup-table-and-define-relationships – 2015-03-29 19:38:58