Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET LINQ
Hello ,
I'm using linq to sql with N-Tiers and i need to returns composite objects from Buisness Layer to Presntation layer
 
I used this Way
public static IQueryable GetComplexResult(int companyId)
    {
        DataClassesDataContext dataContext = new DataClassesDataContext();
        var query = from c in dataContext.Companies
                    join x in dataContext.Positions
                    on c.CreatorPositionId equals x.PositionId
                    select new
                    {
                        c.CompanyName,
                        x.PositionName
                    };
        return query.AsQueryable();
    }
 

Code behinde page
 
IQueryable memberCompanies = Company.GetCompanyWorkingSectorAndServices(MemberSession.MemberId);
        RepeaterCompanies.DataSource = memberCompanies;
        RepeaterCompanies.DataBind();
 
1-Is this the best way to do it?
2-What about the performance ?
 
I don't want to create additional classes to return the value
 
Thank you all Smile | :)
Posted 18-Sep-12 3:40am
mrcooll975
Edited 18-Sep-12 3:41am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
If your value is fix and it will not be change frequently then you can just convert it as ToList and send it between layers. As you have CompanyName and PositionName selection, you can convert it into ToList and pass it on UI for parsing.
 
You can also use List<Dynamic>(Introduce in Dot net framework 4.0) to return your object. The only disadvantage is, you will not get IntelliSense for that.
  Permalink  
Comments
mrcooll at 18-Sep-12 10:08am
   
Thank you for your replay
The Two ways works fine with me "return IQueryable & List "
But i really wants to know what is deference between them from performance perspective
* The values will be fixed , m not gonna change it , its for Repeater rendering
also m gonna set DataContext => ObjectTrackingEnabled = false
digimanus at 18-Sep-12 15:21pm
   
a list object has a lot of overhead was me told once in a reply in article I wrote about disadvantages of sqlparameters
@amitgajjar at 18-Sep-12 22:24pm
   
What to use List/IQueryable/IEnumerable is all depend upon what you are going to do with the return value. all of the above type have different extension methods. If you are only reading the value then i will not suggest you to go for the List instead IEnumerable is more preferable. If you want to query on the return list then i prefer IQueryable instead of IEnumerable. Now you have to decide which one is required in your scenario.
 
Thanks
-Amit Gajjar
@AmitGajjar at 20-Sep-12 2:18am
   
Mark solution as answered if it helps you.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Let this help you to validate your approach:
http://msdn.microsoft.com/en-us/library/bb882671.aspx[^]
  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 310
1 Sergey Alexandrovich Kryukov 166
2 PhilLenoir 164
3 Richard MacCutchan 160
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 6,077
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 18 Sep 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