Linq to sql中如何进行连接查询 [英] Linq to sql in how to make join query

查看:91
本文介绍了Linq to sql中如何进行连接查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var query2 =(来自pd.Student1s中的pd,在pd.id上的db.Test_1s中加入od等于od.No选择新的{od.Name,pd.name})。ToList();





错误:

var query2 = (from pd in db.Student1s join od in db.Test_1s on pd.id equals od.No select new { od.Name, pd.name }).ToList();


Error :

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

推荐答案

看看这个页面,有几个如何使用LINQ的例子:



http://code.msdn.microsoft.com/101- LINQ-Samples-3fb9811b [ ^ ]



希望它可以帮到你。
Have a look at this page, there are several examples of how to use LINQ:

http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b[^]

Hope it helps you.


在这里你可以找到加入LinQ的例子。



C#加入 [ ^ ]



我认为在您的linq查询中问题是由差异引起的pd.id和od.No之间的类型。两列的类型必须相同!



Here you can find examples for join in LinQ.

C# Join[^]

I think in your linq query the problem was caused by the difference of the type between the pd.id and od.No. The type of the two columns must be the same!

var query2 = (from pd in db.Student1s
              join od in db.Test_1s on pd.id equals od.No
              select new 
                {
                    od.Name,
                    pd.name
                }).ToList();


您需要查看以下内容



1. pd.id od.No 属于同一类型。

2.如果任一变量可以为空,则将查询更改为从变量的 Value 属性中读取



这里有一个例子看看



其中一个表达式int join子句的类型不正确。调用加入时类型推断失败[ ^ ]
You need to check the following

1. that pd.id and od.No are the same type.
2. if either variable is nullable that you change the query to read from the Value property of the variables

for an example look here

The type of one of the expressions int he join clause is incorrect. Type inference failed in the call to 'join'[^]


这篇关于Linq to sql中如何进行连接查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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