Click here to Skip to main content
11,648,785 members (85,747 online)
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
mrcooll1.1K
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 F-ES Sitecore 419
1 CPallini 410
2 Kornfeld Eliyahu Peter 330
3 OriginalGriff 324
4 Sergey Alexandrovich Kryukov 254
0 OriginalGriff 1,512
1 Sergey Alexandrovich Kryukov 1,022
2 jyo.net 994
3 DamithSL 986
4 CPallini 945


Advertise | Privacy | Mobile
Web03 | 2.8.150804.4 | Last Updated 18 Sep 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