如何使用linq查询连接3个表 [英] How to join 3 tables using linq query

查看:98
本文介绍了如何使用linq查询连接3个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

加入三张桌子时我收到错误。请任何人解决这个错误。如何从3个表中获取数据。在第二个连接条件中出现错误,表示其中一个连接条件的类型不正确。



我是什么尝试过:



 var query =来自dbContext.SapDumpFebs中的s 
在s上的dbContext.UserDetails中加入你.USER_ID等于u.USER_ID
在s.GL_AC_NO上的dbContext.GlTexts中加入g等于g.GL_AC_NO
选择新的
{
///列来检索
} ;

解决方案

错误意味着您尝试加入的列不是相同的数据类型。你必须确保它们是相同的类型。



因为你说它是导致问题的第二个连接,那么这意味着以下列是不同的数据类型。



SapDumpFeb.GL_AC_NO

GlText.GL_AC_NO



查看这些和确保它们匹配。



或者,如果你不能改变类型,你可以在连接中转换其中一个。例如,如果一个是字符串,您可以将另一个转换为连接中的字符串:



  g  在Convert.ToString(s.GL_AC_NO)上的dbContext.GlTexts等于g.GL_AC_NO 


while joining three tables i am getting error. please solve this error anybody. how to get data from 3 tables.getting error in second join condition says that "the type of one of the join condition is incorrect".

What I have tried:

var query = from s in dbContext.SapDumpFebs
                       join u in dbContext.UserDetails on s.USER_ID equals u.USER_ID
                       join g in dbContext.GlTexts on s.GL_AC_NO equals g.GL_AC_NO
                       select new
                       {
                           /// columns to retrieve
                       };

解决方案

The error means that the columns you are trying to join on are not the same data type. You must ensure they are the same type.

So as you have said it is the second join causing the problem, then that means that the following columns are different data types.

SapDumpFeb.GL_AC_NO
GlText.GL_AC_NO

Check these and make sure they match.

Alternatively, if you can't change the type you may be able to convert one of them in the join. For example, if one is a string you can convert the other to string in the join:

join g in dbContext.GlTexts on Convert.ToString(s.GL_AC_NO) equals g.GL_AC_NO


这篇关于如何使用linq查询连接3个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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