从类型化数据集执行查询结果 [英] Executing query results from a typed dataset

查看:78
本文介绍了从类型化数据集执行查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LINQ to DataSet模型有点新鲜。我写了以下查询:




var query = 来自 c ds.COLLECTION



join < span style ="font-size:xx-small"> cu ds.COLLECTION_UNIT



< span style ="color:#0000ff; font-size:xx-small"> new {c.COLLECTION_ID,c.ACTIVE_YN}



等于 new {cu.COLLECTION_ID,cu.ACTIVE_YN}



join cui ds.COLLECTION_UNIT_ITEM



{cu.UNIT_ID,cu.ACTIVE_YN}



等于 new {cui.UNIT_ID,cui.ACTIVE_YN}



选择 new {c.COLLECTION_NAME,cu.UNIT_NAME,cui.ITEM_NAME};


我想把它放到DataTable中绑定到ComboBox。我看了一些例子,但我无法正确理解语法。我试过这个:


IEnumerable





< DataRow > query2 = 来自 c in ds.COLLECTION.AsEnumerable()



< span style ="color:#0000ff; font-size:xx-small"> join cu ds.COLLECTION_UNIT.AsEnumerable()



new {X = c.Field< 十进制 < span style ="font-size:xx-small">>( " COLLECTION_ID" ),Y = c.Field< String >( " ACTIVE_YN" )}



等于 new {X = cu.Field< 十进制 >( " COLLECTION_ID" ),Y = cu.Field< 字符串 >( " ACTIVE_YN" )}



join cui ds.COLLECTION_UNIT_ITEM.AsEnumerable( )



new {X = cu.Field< 十进制 >( " UNIT_ID" ),Y = cu.Field< 字符串 >( " ACTIVE_YN" )}



等于 new {X = cui。字段< 十进制 >( " UNIT_ID" ),Y = cui.Field< 字符串 >( " ACTIVE_YN" )}



选择 new {X = c.Field< < span style ="color:#2b91af; font-size:xx-small"> String >( " COLLECTION_NAME" ),

Y = cu.Field<



字符串 >( "UNIT_NAME" ),

Z = cui.Field<



字符串 >( " ITEM_NAME" )};




DataTable





dt = query2.CopyToDataTable< DataRow >();


我得到了在'join cui'行上跟随错误:

错误1无法将类型'System.Collections.Generic.IEnumerable< AnonymousType#1>'隐式转换为'System.Collections.Generic.IEnumerable< System。 Data.DataRow>"。存在显式转换(您是否错过了演员?)

我做错了什么?另外我不喜欢语法必须使用 cui.Field< 字符串 >( " ITEM_NAME" vs. cui.UNIT_ID。
这不是使用强类型数据集的重点吗?

谢谢。

解决方案

您可能会在DataSet论坛中获得更好的回复: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataset/threads

Somewhat new to the LINQ to DataSet model.  I have the following query written:

 

var query = from c in ds.COLLECTION

 

join cu in ds.COLLECTION_UNIT

 

on new { c.COLLECTION_ID, c.ACTIVE_YN }

 

equals new { cu.COLLECTION_ID, cu.ACTIVE_YN }

 

join cui in ds.COLLECTION_UNIT_ITEM

 

on new { cu.UNIT_ID, cu.ACTIVE_YN }

 

equals new { cui.UNIT_ID, cui.ACTIVE_YN }

 

select new { c.COLLECTION_NAME, cu.UNIT_NAME, cui.ITEM_NAME };

I would like to put this into a DataTable to bind to a ComboBox.  I have looked at some examples but I am not able to get the syntax correct.  I tried this:


IEnumerable

 

<DataRow> query2 = from c in ds.COLLECTION.AsEnumerable()

 

join cu in ds.COLLECTION_UNIT.AsEnumerable()

 

on new { X = c.Field<Decimal>("COLLECTION_ID"), Y = c.Field<String>("ACTIVE_YN") }

 

equals new { X = cu.Field<Decimal>("COLLECTION_ID"), Y = cu.Field<String>("ACTIVE_YN") }

 

join cui in ds.COLLECTION_UNIT_ITEM.AsEnumerable()

 

on new { X = cu.Field<Decimal>("UNIT_ID"), Y = cu.Field<String>("ACTIVE_YN") }

 

equals new { X = cui.Field<Decimal>("UNIT_ID"), Y = cui.Field<String>("ACTIVE_YN") }

 

select new { X = c.Field<String>("COLLECTION_NAME"),

Y = cu.Field<

String>("UNIT_NAME"),

Z = cui.Field<

String>("ITEM_NAME") };


DataTable

 

dt = query2.CopyToDataTable<DataRow>();

I get the following error on the 'join cui' line:

Error 1 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<AnonymousType#1>' to 'System.Collections.Generic.IEnumerable<System.Data.DataRow>'. An explicit conversion exists (are you missing a cast?) 

What am I doing wrong?  Also I don't like the syntax having to use  cui.Field<String>("ITEM_NAME" vs. cui.UNIT_ID.    
Isn't that the point of using a strongly typed dataset?

Thanks.

解决方案

You might get better responses in the DataSet forum: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataset/threads


这篇关于从类型化数据集执行查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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