c# - LINQ,使用包含函数

标签 c# entity-framework linq linq-to-sql linq-to-entities

我在 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/

相关文章:

LINQ 聚合与嵌套 foreach

c# - 获取嵌套字典中值的总和

c# - 为 IQueryable<T> 生成表达式

c# - 在 asp.net 中使用客户端和服务器验证器仅显示客户端验证

c# - 命名空间 'FriendlyUrls' 中不存在类型或命名空间名称 'Microsoft.AspNet'

c# - 如何以线程安全的方式增加(增加值)小数?

asp.net-mvc - 无法更新标识列 'Unique ID', Entity Framework 错误

c# - Entity Framework 4 中的 Linq 查询。糟糕的性能

c# - 当查询仅因属性不同时,如何解决 LINQ to Entity 查询重复问题?

c# - JSON.Net 是否保证始终以相同的方式序列化?