[英]Entity Framework Code first with models in a different project
Evening, Im sure that this is probably quite simple... but Im doing something wrong. 晚上,我相信这可能很简单......但我做错了。
I am trying to create a solution with 3 (for now) projects: 我正在尝试使用3个(现在的)项目创建一个解决方案:
I want to keep the models in a different project/assembly from the UI and the DAL because the models will be reusable between projects and we may want to swap out the DAL etc without having to mess about with the models etc... 我想将模型保存在UI和DAL的不同项目/程序集中,因为模型可以在项目之间重用,我们可能想要更换DAL等而不必弄乱模型等...
Anyway, onto the problem. 无论如何,解决问题。
I have created a few classes in my models project like : 我在我的模型项目中创建了一些类,如:
public class Client
{
public int ClientID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string PhoneNumber { get; set; }
public string Notes { get; set; }
public virtual Contact BillingContact { get; set; }
public virtual ICollection<Contact> Contacts { get; set; }
public virtual ICollection<Invoice> Invoices { get; set; }
}
I have then created a DBContext in the DAL 然后我在DAL中创建了一个DBContext
using System.Data.Entity;
using DBDS.Invoice.Models;
namespace DBDS.Invoice.DAL.EF
{
public class InvoiceDataContext : DbContext
{
public DbSet<Client> Clients;
}
}
I have enabled migrations on the DAL project, Added a migration and called update-database - the database has been created but with NO tables. 我已经在DAL项目上启用了迁移,添加了一个迁移并调用了update-database - 数据库已经创建但没有表。
Anyway, Im sure Im being dense - any help will be appreciated. 无论如何,我确定我是密集的 - 任何帮助将不胜感激。
Thanks 谢谢
Clients
needs to be a property for Entity Framework to pick it up Clients
需要成为实体框架的一个属性才能获取它
public class InvoiceDataContext : DbContext
{
public DbSet<Client> Clients { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.