我有現有的其基於對象上下文.NET應用4。 現在我在對現有應用程序添加的DbContext通過繼承的DbContext和調用構造方法,並將現有的對象上下文。即添加的DbContext到現有的.NET應用程序4
public class DemoModelEntitiesDbContext : DbContext
{
public DemoModelEntitiesDbContext():base(new DemoModelEntities(), dbContextOwnsObjectContext:true)
{
}
public DbSet<ELMAH_Error> ELMAH_Error { get; set; }
}
比我打電話,
using (DemoModelEntitiesDbContext context = new DemoModelEntitiesDbContext())
{
foreach (ELMAH_Error entity in context.ELMAH_Error.ToList())
{
Console.WriteLine(entity.ID);
}
}
我收到以下錯誤消息, 「類型‘ObjectContextDemo.ELMAH_Error’沒有被映射。檢查類型尚未明確排除使用Ignore方法或NotMappedAttribute數據註釋。驗證類型被定義爲一類,是不是原始的,嵌套的或通用的,並且不從EntityObject繼承「。 我檢查了我的現有實體是從EntityObject繼承的。 如何添加的DbContext到現有的應用程序,而不是改變現有的代碼?