Click here to Skip to main content
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></master></master></dataaccount></dataaccount>
Posted 4-Oct-12 21:49pm
Edited 4-Oct-12 22: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 OriginalGriff 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2014
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