将dlinq查询结果转换为datatable时,DataSet不支持System.Nullable [英] DataSet does not support System.Nullable while converting dlinq query result to datatable

查看:81
本文介绍了将dlinq查询结果转换为datatable时,DataSet不支持System.Nullable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使用Dlinq查询从SQL Server检索数据


我的数据库包含2个表患者和调查。患者是主表,调查是儿童表。这两个表都与一个关键的PID相关


我正在使用.net 2005和2005年的linq预览从这些表中获取数据。我在.dlinq文件中生成了datacontext,Patient和survey类



< p align = left> 我的查询


var result = from p in db.Patients from s in p.SurveyResends选择 new {P.PID,s.SID} ;



PID和SID是两者都是数据库中的int类型。在dlinq文件中,数据库的类型都是< nullable> int。



当我尝试将结果转换为Datatable时,它会抛出" DataSet不支持System.Nullable<>。"错误。


DataTable dt = result.ToDataTable();



如果我们尝试在dlinq查询中仅检索PID,它就可以从父表中工作。但是当我们尝试从子表中获取SID时,它会抛出错误。



如果有人之前遇到过此类问题或解决方案,请告诉我。



提前致谢


问候,


Sachin

解决方案


您可以尝试为投影字段指定默认值:



var result = from p in db.Patients来自s p.SurveyResends选择 new {P.PID ?? 0,s.SID ?? 0};



Hi,

 

I am trying to retrieve data from SQL Server using Dlinq queries

My Database contains 2 tables Patients and Surveys. Patients is a master table and surveys is a child table. Both the tables are related on a key PID

I am using .net 2005 and linq preview may 2005 to fetch data from these tables. I have generated datacontext, patient and survey classes in .dlinq file

 

My Query is

var result = from p in db.Patients from s in p.SurveyResends select new {P.PID,s.SID};

 

PID and SID are both of type int in database. In dlinq files,type of both the database is <nullable> int.

 

When I try to convert result to Datatable, it throws "DataSet does not support System.Nullable<>." error.

DataTable dt=result.ToDataTable();

 

If we try to retrieve just PID in the dlinq query it works i.e. from the parent table. but when we try to fetch SID from child table it throws above error.

 

Please let me know if anyone have faced such type of issue before or the solution for this.

 

Thanks in Advance

Regards,

Sachin

解决方案

 

You can try to give the projection fields a default value:

 

var result = from p in db.Patients from s in p.SurveyResends select new {P.PID ?? 0,s.SID ?? 0};

 


这篇关于将dlinq查询结果转换为datatable时,DataSet不支持System.Nullable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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