显示long的linq查询在将sql查询转换为linq时不包含Contains的定义

时间:2022-09-22 20:50:41

friends we are converting sql query to linq query, this conversion is involving two tables as follows

朋友们我们正在将sql查询转换为linq查询,这个转换涉及两个表如下

select * from Tbl_Vulpith_Registration where Profile_Pic is not null and MemId IN(select MemId from Tbl_List_Services)

here Tbl_Vulpith_Registration and Tbl_List_Services both are the tables

这里Tbl_Vulpith_Registration和Tbl_List_Services都是表

memId is the common column in the both the tables.

memId是两个表中的公共列。

following the what we tried to convert the above sql query to linq

以下我们尝试将上面的sql查询转换为linq

var reglist=  objentity.Tbl_Vulpith_Registration.Select(a => a).Where(a => a.Profile_Pic != null);
// var res= reglist.Where(a=>a.Tbl_List_Services)

var listmemsmemIds = objentity.Tbl_List_Services.Select(b => b.MemId).ToList();

var finalist = reglist.Select(b => b).Where(c => c.MemId.Contains(listmemsmemIds));

We've tried multiple ways to convert but no luck.

我们尝试了多种转换方法,但没有运气。

2 个解决方案

#1


1  

You need to do the exact opposite:

你需要完全相反:

.Where(c => listmemsmemIds.Contains(c.MemId))

#2


0  

Use the below code which join two tables and fetch the output (internally, it will create only one query)

使用以下代码连接两个表并获取输出(在内部,它将只创建一个查询)

var reglist = objentity.Tbl_Vulpith_Registration.Join(objentity.Tbl_List_Services, 
     o => o.MemId, i => i.MemId, (o, i) => o).Where(o => o.Profile_Pic  != null).ToList()

The above code correlates the tables based on matching MemId and return the object of entity type of Tbl_Vulpith_Registration.

上述代码基于匹配的MemId关联表,并返回实体类型为Tbl_Vulpith_Registration的对象。

If you want to read about Join method, check this link.

如果您想阅读有关Join方法的信息,请查看此链接。

#1


1  

You need to do the exact opposite:

你需要完全相反:

.Where(c => listmemsmemIds.Contains(c.MemId))

#2


0  

Use the below code which join two tables and fetch the output (internally, it will create only one query)

使用以下代码连接两个表并获取输出(在内部,它将只创建一个查询)

var reglist = objentity.Tbl_Vulpith_Registration.Join(objentity.Tbl_List_Services, 
     o => o.MemId, i => i.MemId, (o, i) => o).Where(o => o.Profile_Pic  != null).ToList()

The above code correlates the tables based on matching MemId and return the object of entity type of Tbl_Vulpith_Registration.

上述代码基于匹配的MemId关联表,并返回实体类型为Tbl_Vulpith_Registration的对象。

If you want to read about Join method, check this link.

如果您想阅读有关Join方法的信息,请查看此链接。