LINQ to SQL-一些值返回null [英] LINQ to SQL - Some values coming back null

查看:78
本文介绍了LINQ to SQL-一些值返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var matchingRequests = from r in db.Requests
                       where r.ID == (requestID)
                       select new Req((string)r.ID.ToString(), (string)r.Project_Title.ToString(), (string)r.Staff_ID.ToString(), (decimal)r.Request_Amount, (string) r.Disposition.ToString());
return matchingRequests.ToList()



我得到r.ID,r.Project_Title和r.Disposition的值.但是,Staff_ID和Request_Amount都返回为空.

我已将LINQ生成的SQL粘贴到SQL Man Studio中,并运行查询以验证是否确实存在人员和数量值.

任何人都不知道为什么这些字段会返回null/0吗?

解决方案

您总是可以在where 条款中包含一些条件以检查null-就像


最后是我的一个愚蠢的错误-我的Iservicename文件的支持出现问题.


var matchingRequests = from r in db.Requests
                       where r.ID == (requestID)
                       select new Req((string)r.ID.ToString(), (string)r.Project_Title.ToString(), (string)r.Staff_ID.ToString(), (decimal)r.Request_Amount, (string) r.Disposition.ToString());
return matchingRequests.ToList()



I get values back for r.ID, r.Project_Title, and r.Disposition. Both Staff_ID and Request_Amount, however, come back as null.

I have pasted the SQL generated from LINQ into SQL Man Studio and ran the query to verify that there are indeed values for both staff and amount.

Anyone have any idea why these fields are coming back null / 0 ?

解决方案

You can always include some conditions in the where clause to check for null - just like you would do in a normal query.


Ended up being a stupid mistake on my part - there was a problem in strut of my Iservicename file.


这篇关于LINQ to SQL-一些值返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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