EntitySpaces 2012查询以选择Distinct Rows [英] EntitySpaces 2012 query to select Distinct Rows

查看:65
本文介绍了EntitySpaces 2012查询以选择Distinct Rows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EntitySpaces 2012架构,该架构提供ORM映射和内置方法,使用它的库编写SQL查询(就像LINQ to SQL一样)。问题是,我无法使用EntitySpaces Select Query从表中选择不同的行。目前,我的工作如下



 DataTable dt =  new 数据表(); 
ActualData objAct = new ActualDataQuery();
objAct.Select(objAct.Year.Distinct);
dt = objAct.LoadDataTable();
if (dt.Rows.Count > 0
{
FillCombo(dt);
}



我在我的数据表对象加载的行上也设置了一个断点,它显示了多个不同的行存在多个时间(意味着明显不起作用)。

http://i.stack.imgur.com/ RXYiA.jpg [ ^ ]



我还查看了EntitySpaces的完整文档,但没有关于distinct关键字的内容。此外,我在互联网上找不到与此问题相关的任何内容,因为EntitySpaces2012没有论坛。任何帮助都将非常感激!

解决方案

这样做:



 DataTable realData; 
DataTable dt = new DataTable();
ActualData objAct = new ActualDataQuery();
objAct.Select(objAct.Year.Distinct);
dt = objAct.LoadDataTable();

realData = dt.DefaultView.ToTable( true );

if (realData.Rows.Count > 0
{
FillCombo(realData);
}





DataView具有ToTable方法。第一个参数定义返回的行是否必须是不同的(true),第二个参数是列表列表,应该通过哪个行进行区分。



您的新数据表将具有单列名为Year,将包含您视图中的不同值。





如果这有帮助,请花时间接受解决方案。谢谢。


使用 Linq [ ^ ]:

< pre lang =c#> var qry = objAct.Select(x => x.Year).Distinct();
dt = qry.CopyToDataTable();
FillCombo(dt);





有关详细信息,请参阅:101 LINQ样本 [ ^ ]





EntitySpaces:

选择不同的 [ ^ ]

< a href =http://esdocs.pixeo.be/default.htm?turl=Modules%2F4%2FXMLDocuments%2FReference%2Fhtml%2FM_EntitySpaces_DynamicQuery_esQueryItem_Distinct.htm>不同的方法 [ ^ ]



它可能如下所示:

 DataTable dt =  new  DataTable(); 
ActualData objAct = new ActualDataQuery();
objAct.Distinct = true ;
objAct.Select(objAct.Year);
dt = objAct.LoadDataTable();


I am using EntitySpaces 2012 architecture which provides ORM mapping and built-in methods to write your SQL query using it's libraries (just like LINQ to SQL). The problem is, I cannot select distinct rows from a table using EntitySpaces Select Query. Currently, I am doing it as follows

DataTable dt = new DataTable();
ActualData objAct = new ActualDataQuery();
objAct.Select(objAct.Year.Distinct);
    dt = objAct.LoadDataTable();
if (dt.Rows.Count > 0)
{
    FillCombo(dt);
}


I have put a breakpoint as well on the line where my datatable object is getting load, and it is showing that the distinct rows are present there multiple times (means distinct not working).
http://i.stack.imgur.com/RXYiA.jpg[^]

I have also go through the complete documentation of EntitySpaces but there's nothing regarding distinct keyword. Also I found nothing on the internet related to this problem as there's no forum for EntitySpaces2012. Any help would be hugely appreciated!

解决方案

Do this:

DataTable realData;
DataTable dt = new DataTable();
ActualData objAct = new ActualDataQuery();
objAct.Select(objAct.Year.Distinct);
    dt = objAct.LoadDataTable();

realData = dt.DefaultView.ToTable(true, "Year");

if (realData.Rows.Count > 0)
{
    FillCombo(realData);
}



DataView has ToTable method. First parameter defines if the rows returned need to be distinct (true) and the second is column list by which distinct should be done.

Your new datatable will have single column named Year which will contain distinct values from your view.


If this helps please take time to accept the solution. Thank you.


Using Linq[^]:

var qry = objAct.Select(x=>x.Year).Distinct();
    dt = qry.CopyToDataTable();
    FillCombo(dt);



For further information, please see: 101 LINQ Samples[^]

[EDIT]
EntitySpaces:
select distinct[^]
Distinct method[^]

It might look like:

DataTable dt = new DataTable();
ActualData objAct = new ActualDataQuery();
objAct.Distinct = true;
objAct.Select(objAct.Year);
dt = objAct.LoadDataTable();


这篇关于EntitySpaces 2012查询以选择Distinct Rows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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