【问题标题】:LINQ CROSS JOIN ErrorLINQ 交叉连接错误
【发布时间】:2014-03-08 22:25:12
【问题描述】:

我收到了这个错误

System.Data.Objects.ObjectQuery`1[XXX.Model.Cust_ProfileTbl]”类型的对象不能 转换为类型 'System.Data.Entity.DbSet`1XXX.Core.Model.Cust_ProfileTbl]'。

当我尝试使用 LINQ CROSS JOINing 这两个表时。谁能建议我该怎么做?

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

【问题讨论】:

    标签: c# sql linq


    【解决方案1】:
    var test =
    from cg in service.DBContext.Cust_GroupTbls
    from c in service.DBContext.Cust_ProfileTbls
    select new { intCustGroup = cg.intCustGroup, bintAccountNo = c.bintAccountNo };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-24
      • 1970-01-01
      • 2020-10-07
      • 2017-01-26
      • 1970-01-01
      • 2014-03-17
      • 2011-06-10
      • 1970-01-01
      相关资源
      最近更新 更多