简体   繁体   中英

Entity Framework code first - Derived class not in the same assembly as the base class

I have the following structure:

  • Base Entities (contains abstract MyBaseClass)
  • Interfaces
  • Concrete Implementation (contains MyClass : MyBaseClass)
  • EF project (references all of the above projects)

When I try to enable migrations on the EF project (in order to generate database script), I get the following:

The abstract type MyBaseClass has no mapped descendants and so cannot be mapped. Either remove MyBaseClass from the model or add one or more types deriving from MyBaseClass to the model

What can I do to make EF look into its references to find my derived class? No Fluent API.

Base Entities assembly:

abstract class MyBaseClass

Concrete Implementation assembly:

class MyClass : MyBaseClass

Interfaces assembly:

IDbSet<MyBaseClass> WhateverName

When I run Enable-Migrations -ConnectionStringName "EfDataRepository" EF complains that it can't find derived classes of MyBaseClass.

See the answer to this question . That states that you need a concrete type to save to the database. It also gives an example of the sort of code context I was referring to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM