动态列选择 [英] Dynamic Columns Selection

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

问题描述

亲爱的代码项目,

我正在使用c#和Linq to Entities with SQL Server.使用此方法编写查询时遇到问题.

以下是我目前的代码.

Dear Code project,

I am using c# , Linq to Entities with SQL server. I have a problem while writing a query using this.

Following is my present code.

private List<DataAccount> GetDataAccountDetails()
{
PIAEntities piaentity = new PIAEntities(strConn);

List<DataAccount>dataAccou nt = (from p in piaentity.DataAccounts
               where p.FollowUpRequired == true && p.PreviousOwener == UserName        &&p.FollowUpOn < DateTime.Now
                              select p).ToList<DataAccount>();

}



执行完此查询后,它将重新将整个数据库列都返回到DataGrid视图.但是我的客户希望他应该可以选择仅选择列数.这意味着用户将在datagrid视图中的某些位置过滤某些列.我需要将其传递给上面的查询,并仅获取那些列.

有了上述要求,它应该



After execution of this query it is returing entire database columns to DataGrid View. But my Client is expecting like he should have an option to select number of columns only. This means user will filter some columns some where from the datagrid view. I need to pass it to the above query and get those columns only.

With the above request it should like

private List<DataAccount> GetDataAccountDetails(string[] columns)
{
PIAEntities piaentity = new PIAEntities(strConn);

List<DataAccount>dataAccou nt = (from p in piaentity.DataAccounts
               where p.FollowUpRequired == true && p.PreviousOwener == UserName        &&p.FollowUpOn < DateTime.Now
                              select p).ToList<DataAccount>();

}


参数可以是string []或只能是string.没有问题.仅基于传递的参数,我需要过滤并获取结果.

希望清楚地说明了.提前谢谢.

chowdary.


the paramenter can be either string[] or only string. No Issues. Based on the passed paraments only i need to filter and get the results.

Hope explined clearly. Thanks in advance.

chowdary.

推荐答案

尝试以下操作:
Try this:
private List<dataaccount> GetDataAccountDetails(string[] columns)
{
    PIAEntities piaentity = new PIAEntities(strConn);
     
    var nt = from p in piaentity.DataAccounts
                                     where p.FollowUpRequired == true 
                                     && p.PreviousOwener == UserName   
                                     && p.FollowUpOn < DateTime.Now
                                     select new{
                                            Column1 = p.Column1,
                                            Column2 = p.Column2,
                                            Column3 = p.Column3,
                                            Column4 = p.Column4,
                                     };
    var customList = MakeList(nt);

}
public static List<T> MakeList<T>(T itemOftype)
{
    List<T> newList = new List<T>();
    return newList;
}   





--Amit





--Amit


请参阅下面的链接

http: //weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx [
See below link

http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx[^]


这篇关于动态列选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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