Click here to Skip to main content
11,703,631 members (67,371 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# LINQ SQL Server 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;
 

       }


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>
Posted 4-Oct-12 20:49pm
Edited 4-Oct-12 21:00pm
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 570
1 OriginalGriff 500
2 Sergey Alexandrovich Kryukov 410
3 F-ES Sitecore 165
4 Andy Lanng 159
0 OriginalGriff 8,519
1 Sergey Alexandrovich Kryukov 7,667
2 CPallini 4,987
3 Maciej Los 4,686
4 Mika Wendelius 3,566


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100