c# - LINQ 交叉连接错误

标签 c# sql linq

我遇到了这个错误

Object of type 'System.Data.Objects.ObjectQuery`1[XXX.Model.Cust_ProfileTbl]' cannot be converted to type 'System.Data.Entity.DbSet`1XXX.Core.Model.Cust_ProfileTbl]'.

当我尝试使用 LINQ CROSS JOIN对这 2 个表进行操作时。谁能建议我该怎么做?

var Cust_ProfileTbl = service.DBContext.Set<Cust_ProfileTbl>();
var Cust_GroupTbl = service.DBContext.Set<Cust_GroupTbl>();

var test =
from cg in Cust_GroupTbl
from c in Cust_ProfileTbl
select new { intCustGroup = cg.intCustGroup, bintAccountNo = c.bintAccountNo };

Cust_ProfileTbl.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace XXXX.Core.Model
{
    [Table("Cust_ProfileTbl")]
    public partial class Cust_ProfileTbl  
    {
        [Key]
        public long bintAccountNo { get; set; }
    }
}

Cust_GroupTbl.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace xxxx.Core.Model
{
    [Table("Cust_GroupTbl")]
    public partial class Cust_GroupTbl
    {
        [Key]
        public int intCustGroup { get; set; } 
    }
}

最佳答案

var test =
from cg in service.DBContext.Cust_GroupTbls
from c in service.DBContext.Cust_ProfileTbls
select new { intCustGroup = cg.intCustGroup, bintAccountNo = c.bintAccountNo };

关于c# - LINQ 交叉连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21696687/

相关文章:

sql - 使用 SQL 有效地反转外键

php - sql LIKE 有问题

c# - 正则表达式匹配 C# 代码中的 SQL 关键字

c# - 如何将多个列表项合并为一个项目?

mysql - 无法识别使用 MAX 和 OVER PARTITION BY 的语法问题

c# - 简化 Linq 表达式

javascript - 拖放到数据库 mvc 后保存图像顺序

c# - Linq XDocument 返回基于 2 个属性值的元素列表

c# - 控件上的透明图像

c# - 写入在 Excel 中打开的文件