0
我试图选择数据库aswel中的所有项目作为使用实体框架的所有依赖项。从数据库中选择项目加上所有依赖项
执行选择时出现以下错误 指定的包含路径无效。 EntityType'RequestModel.RequestType'不声明名为'FieldDefinitions,ListItems'的导航属性。
这是我的代码,林肯定它的东西简单即时通讯失踪。
var reqs = new List<RequestType>();
using (var db = new ITISS_RequestEntities())
{
reqs = db.RequestTypes.Include("FieldDefinitions,ListItems").ToList();
}
这里,你使用虚拟ICollections所以一切都应该是可以通过延迟加载反正我的模型
public partial class RequestType
{
public RequestType()
{
this.Requests = new HashSet<Request>();
this.FieldDefinitions = new HashSet<FieldDefinition>();
}
public int RequestType1 { get; set; }
public string TypeDescription { get; set; }
public virtual ICollection<Request> Requests { get; set; }
public virtual ICollection<FieldDefinition> FieldDefinitions { get; set; }
}
public partial class FieldDefinition
{
public FieldDefinition()
{
this.EntryDefinitions = new HashSet<EntryDefinition>();
this.ListItems = new HashSet<ListItem>();
this.RequestTypes = new HashSet<RequestType>();
}
public int RequestField { get; set; }
public string FieldName { get; set; }
public string FieldReference { get; set; }
public string ControlType { get; set; }
public virtual ICollection<EntryDefinition> EntryDefinitions { get; set; }
public virtual ICollection<ListItem> ListItems { get; set; }
public virtual ICollection<RequestType> RequestTypes { get; set; }
}
public partial class ListItem
{
public ListItem()
{
this.FieldDefinitions = new HashSet<FieldDefinition>();
}
public int ListItemID { get; set; }
public string ItemName { get; set; }
public virtual ICollection<FieldDefinition> FieldDefinitions { get; set; }
}
只是为了让事情更清楚小有一点,使用实体框架5.实体框架6.获得的类型,你提到的选项是林“System.Linq.Queryable.Select(System.Linq.IQueryable ,System.Linq.Expressions.Expression >)'的参数无法从使用情况中推断出来。尝试明确指定类型参数。 –
Ernie
你可以在EF5中使用它们,如果你在顶部包含“using”的话 - 正如我指定的那样:) –
感谢你,因为RequestType不包含ListItems的定义 – Ernie