指定的模式无效。错误:由于类型不可用,关系未加载 [英] Schema specified is not valid. Errors: The relationship not loaded because the type is not available

查看:513
本文介绍了指定的模式无效。错误:由于类型不可用,关系未加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有实体依赖关系,产品和访问。依赖关系连接到产品和访问。当我尝试使用以下方式创建一个Access对象时:

  this.context.CreateObjectSet< Access>(); 

它的工作...但是当我尝试创建一个对象集的产品我得到这个错误:指定的模式无效。错误:Model.FK_Product_Dependency的关系未加载,因为Model.Dependency类型不可用。



任何想法?



OBS:我正在使用数据库到模型,并使用EF 4.0



POCO实体:

  public class Dependency 
{
public virtual int Id {get;组; }
public virtual int IdParent {get;组; }
public virtual string Name {get;组; }
public virtual decimal类型{get;组; }
public virtual Dependency Parent {get;组; }
}

public class Product
{
public virtual int Id {get;组; }
public virtual int IdDependency {get;组; }
public virtual decimal类型{get;组; }
public virtual string Name {get;组; }
public virtual string Obs {get;组; }
public virtual Dependency Dependency {get;组;
}

public class Access
{
public virtual int Id {get;组; }
public virtual int IdProfile {get;组; }
public virtual string Name {get;组; }
public virtual Profile Profile {get;组; }
public virtual ICollection<依赖关系>依赖关系{get;组; }
}


解决方案

已解决。 所以,如果互相访问,POCO实体不能使用不同的命名空间/ dll。在上面的例子中,依赖关系和访问是在一个命名空间/ dll和另一个的产品。我认为只有必要的POCO实体与EF映射的实体相同(属性和名称),但实体必须在相同的命名空间/ dll(仅限于访问对方的实体)。


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; }
}

解决方案

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).

这篇关于指定的模式无效。错误:由于类型不可用,关系未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆