联接子句中的类型前pressions之一是实体框架不正确 [英] The type of one of the expressions in the join clause is incorrect in Entity Framework

查看:119
本文介绍了联接子句中的类型前pressions之一是实体框架不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在试图执行这个查询:

var query = from dpr in ctx.DPR_MM
            join q in ctx.QOT on dpr.DPR_QOT_ID equals qot_id
            join p in ctx.PAY_MM on new { q.QOT_SEC_ID, dpr.DPR_TS } equals new { p.PAY_SEC_ID, p.PAY_DATE }
            where q.QOT_ID = qot_id
            select new
            {
                dpr.dpr_ts,
                dpr.dpr_close,
                pay.First().pay_dividend
            };

我得到这个错误:

I'm getting this error:

联接子句中的类型前pressions之一是不正确。
  类型推断在调用失败加入。

The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.

QOT_SEC_ID 的类型为小数 PAY_SEC_ID 是类型 INT32
我不能改变它在表上。

QOT_SEC_ID is of type decimal and PAY_SEC_ID is of type int32. I'm not allowed to change it in the table.

不管我做什么,我不能改变它在模型的属性。
我曾尝试转换的类型如下:

No matter what I do, I'm not able to change it in model's properties. I have tried to convert the types like this:

join p in ctx.PAY on new { sec_id = (Int32)(q.QOT_SEC_ID), dpr.DPR_TS } equals new { sec_id = (Int32)p.PAY_SEC_ID, p.PAY_DATE }

但得到上述错误。

but getting the error above.

推荐答案

类型的属性的匿名类型的名称必​​须匹配:

The types and the names of the properties in the anonymous types must match:

new { p1 = q.QOT_SEC_ID, p2 = dpr.DPR_TS } 
    equals 
new { p1 = (decimal)p.PAY_SEC_ID, p2 = p.PAY_DATE }

p.PAY_SEC_ID 是一个 INT

new { p1 = (int?)q.QOT_SEC_ID, p2 = dpr.DPR_TS } 
    equals 
new { p1 = p.PAY_SEC_ID, p2 = p.PAY_DATE }

这篇关于联接子句中的类型前pressions之一是实体框架不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆