Linq到实体的数据检索 [英] Data Retreival in Linq to Entities

查看:61
本文介绍了Linq到实体的数据检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在写一个小应用程序.它仅包含一个称为master的表.这包含大约280个字段,我正在使用Linq to Entities来使用.

以下是代码.

Hello,

I am writing a small application. This contains only one table called master. This contains about 280 fields and i am using Linq to Entities to use.

Following is the code.

List<Master> dataAcc = new List<Master>();
       public MainWindow()
       {
           InitializeComponent();
           dataAcc = Getmembers();
        }

       public List<Master> Getmembers()
       {
           BillingEntities billEntity = new BillingEntities(DataAccess.GetConnectionStringForSelectedPractice("MyDB"));

           List<Master> dataAccount = (from p in billEntity.DataAccounts
                                            where p.Duplicate == false
                                            select p
                                            ).Take(1000).ToList<Master>();

           return dataAccount;


       }




实际上,我只需要280列中的三列,但是Linq to Entities不接受像linq to sql这样的方式编写代码.




Actually i need only three columns out of 280 columns but Linq to Entities is not accepting to write code in the following way as like linq to sql.

 List<master> dataAcc = new List<Master>();
        public MainWindow()
        {
            InitializeComponent();
            dataAcc = Getmembers();
         }

        public List<master> Getmembers()
        {
            BillingEntities billEntity = new BillingEntities(DataAccess.GetConnectionStringForSelectedPractice("MyDB"));

            List<master> dataAccount = (from p in billEntity.DataAccounts
                                             where p.Duplicate == false
                                             select new Master
{
  AcctNumber = p.AcctNumber,
  Name = p.Name,
  BirthDay = p. DOB
}
).Take(1000).ToList<master>();

return dataAccount;
}

Is it possible to acheive this????

chowdary.</master></master></master></dataaccount></dataaccount>

推荐答案



我建议您为此目的创建一个新的数据持有人"类,该类仅具有您 Master 类的几个属性(就您而言,是AcctNumber,Name和BirthDay)!
例如,您可以将其命名为 SimpleMatserDTO 并将其用作方法中的返回类型...
Hi,

I suggest you to create new "dataholder" class for that purpose, which will have only few properties (AcctNumber, Name and BirthDay in your case) of your Master class!
You can name it SimpleMatserDTO for example or similar and use it as return type in your method...


这篇关于Linq到实体的数据检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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