Schema specified is not valid. Errors: The relatio

2019-07-20 04:05发布

问题:

I have the entities Dependency, Product and Access. Dependency is connected to Product and Access. When i try to create a object set of Access with:

this.context.CreateObjectSet<Access>();

It's working... but when i try to create a object set of Product i get this error: Schema specified is not valid. Errors: The relationship 'Model.FK_Product_Dependency' was not loaded because the type 'Model.Dependency' is not available.

Any ideas?

OBS: i'm working with Database to Model, and with EF 4.0

POCO Entities:

public class Dependency
{
    public virtual int Id { get; set; }
    public virtual int IdParent { get; set; }
    public virtual string Name { get; set; }
    public virtual decimal Type { get; set; }
    public virtual Dependency Parent { get; set; }
}

public class Product
{
    public virtual int Id { get; set; }
    public virtual int IdDependency { get; set; }
    public virtual decimal Type { get; set; }
    public virtual string Name { get; set; }
    public virtual string Obs { get; set; }
    public virtual Dependency Dependency { get; set; }
}

public class Access
{
    public virtual int Id { get; set; }
    public virtual int IdProfile { get; set; }
    public virtual string Name { get; set; }
    public virtual Profile Profile { get; set; }
    public virtual ICollection<Dependency> Dependencies { get; set; }
}

回答1:

Solved. So, the POCO entities cannot be in different namespaces/dlls if access each other. In the exemple above, Dependency and Access was in a namespace/dll and Product in another. I thought that was only necessary the POCO entity be the same (properties and name) like the entity mapped by EF, but is necessary that the entities are in the same namespace/dll (only to the entities that access each other).