我在 Visual Studio 2013 中使用 EF 6。我想代表子表中的外键从父表中获取匹配记录。 我有以下代码行
var record = db.ChannelFees.Include(x =>x.SubSource).ToList();
这里ChannelFees是SubSourceId是外键的子表 子源(父表)。
channel 费用等级如下:
using System;
using System.Collections.Generic;
public partial class ChannelFee
{
public virtual SubSource SubSource { get; set; }
public int SubSource_id { get; set; }
public double Fee { get; set; }
public int Id { get; set; }
}
和 SubSource 类
using System;
using System.Collections.Generic;
public partial class SubSource
{
public int Id { get; set; }
public string Description { get; set; }
public string MapName { get; set; }
}
但我收到以下异常。
A specified Include path is not valid. The EntityType 'FinancialManagmentModel.ChannelFee' does not declare a navigation property with the name 'SubSource'.
有什么问题吗?
最佳答案
我认为应该是:
public virtual ICollection<SubSource> SubSource;
关于c# - LINQ,使用包含函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34171999/