LINQ查询实体模型无法正常工作 [英] LINQ querying a entity model not working

查看:57
本文介绍了LINQ查询实体模型无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过LINQ查询我的实体模型/数据库,通过使用同一个表的FK_ID来获取PK_ID。



I tried LINQ querying my entity model/database to get the PK_ID by using the FK_ID of the same table.

var sessid = attend.tblSessions.Where(u => u.FK_GroupID == id).Select(u => u.PK_SessionsID);

MessageBox.Show(sessid.ToString());





参加是模型

id 是通过其他方式提供的,是正确的值。



when消息框显示它给了我



attend is the model
id is supplied by other means and is the correct value that is needed.

when the message box displays it gives me

SELECT
[Extent1].[PK_SessionsID] AS [PK_SessionsID]
FROM [dbo].[tblSessions] AS [Extent1]
WHERE [Extent1].[FK_GroupID] = @p__linq__0





而不是PK_ID的值



我们将非常感谢任何帮助...



and not the value of the PK_ID

Any help will be greatly appreciated...

推荐答案

有一个或多个记录未显示在messageBox中





其中(u => u.FK_GroupID == id)。选择(u => u.PK_SessionsID)





试试这个



var sessid = attend.tblSessions.Where (u => u.FK_GroupID == id)。选择(u => u.PK_SessionsID).FirsrOrDefault();



MessageBox.Show(sessid。服务条款tring());









看看会是什么类型用sessid返回
There is one or more records not displayed in messageBox


Where(u => u.FK_GroupID == id).Select(u => u.PK_SessionsID)


Try This

var sessid = attend.tblSessions.Where(u => u.FK_GroupID == id).Select(u => u.PK_SessionsID).FirsrOrDefault();

MessageBox.Show(sessid.ToString());


or

See what type will return with sessid


这篇关于LINQ查询实体模型无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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