【发布时间】:2017-03-03 18:42:26
【问题描述】:
我正在为连锁餐厅构建一个管理门户。我正在使用 ASP.NET MVC 和 EF Code First。
我希望每个用户在登录后只能看到与其连接的资源。我想在 ApplicationUser 和 Restaurant-class(model) 之间放置一个联结表(多对多),因为每个用户可以在许多餐馆拥有/工作,并且每个餐馆可以有许多所有者/工人。
您如何首先在 EF 代码中执行此操作?就像我做餐厅一样——>菜单?您是否需要为 Applicationuser 构建一个新的 DBContext 才能使其工作?
public class Restaurant
{
public int Id { get; set; }
public string Name { get; set; }
public string Adress { get; set; }
public string PhoneNumber { get; set; }
public DateTime StartDate { get; set; }
//Connections
public virtual ICollection<Menue> Menues { get; set; }
}
public class Menue
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
public DateTime ModifyDate { get; set; }
//FK For RestaurantConnection
public int RestaurantId { get; set; }
}
【问题讨论】:
标签: c# asp.net asp.net-mvc entity-framework