Click here to Skip to main content
13,191,877 members (55,332 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
        return query.AsQueryable();

Code behinde page

IQueryable memberCompanies = Company.GetCompanyWorkingSectorAndServices(MemberSession.MemberId);
        RepeaterCompanies.DataSource = memberCompanies;

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 :)
Posted 18-Sep-12 3:40am
Updated 18-Sep-12 3:41am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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.
mrcooll 18-Sep-12 10:08am
Thank you for your replay
The Two ways works fine with me "return IQueryable & List<dynamic> "
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 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 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.

-Amit Gajjar
@AmitGajjar 20-Sep-12 2:18am
Mark solution as answered if it helps you.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Let this help you to validate your approach:[^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171017.2 | Last Updated 18 Sep 2012
Copyright © CodeProject, 1999-2017
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