Anyone know any good LINQ resources?

  • Hi all . . .

    I'm working on a project that uses ASP.NET MVC2. (I've been learning MVC on the fly, which really makes this a challenge for me.)

    I'm particularly struggling with accessing data using LINQ (not my choice, mind you). My environment uses an entity framework data source. I don't have any specific questions per se; what I could really use is a primer to give me a better idea of how this ties all together.

    Can anyone suggest any good reference resources or tutorials on LINQ?

    Thanks!

    +--------------------------------------------------------------------------------------+
    Check out my blog at https://pianorayk.wordpress.com/

  • This one looks to cover several concepts / topics.

    [/url]

    And I usually find some of the things on MSDN pretty good.

    LINQ kind of intrigued me at first, but I quickly saw some limitations (like no outside join) that would limit usage in my environment.

    That was real early in its lifecycle, so things could have changed.

    Greg E

  • Greg Edwards-268690 (10/13/2010)


    LINQ kind of intrigued me at first, but I quickly saw some limitations (like no outside join) that would limit usage in my environment.

    I hear you; unfortunately, I haven't been given much of a choice.

    So far, I have mixed feelings about LINQ. On the one hand, as a developer, I can see how it's supposed to make things easier, but at the same time, I also recognize that it has limitations. Right now, in my mind, the jury's out.

    +--------------------------------------------------------------------------------------+
    Check out my blog at https://pianorayk.wordpress.com/

  • So are you talking general Linq or Linq to SQL?

    You can do an outer join in Linq it's just not intuitive. Here's an example:

    from c in context.Citizenships join

    cdt in context.Citizenship_Document_Types on c.Country_Code equals cdt.Country_Code

    from cd in context.Citizenship_Documents.Where(cd => cd.Citizenship_Id == c.Citizenship_ID && cdt.Citizenship_Document_Type_Id == cd.Citizenship_Document_Type_Id).DefaultIfEmpty()

    from ia in context.Issuing_Authorities.Where(ia => cd.Issuing_Authority_Id == ia.Issuing_Authority_Id).DefaultIfEmpty()

    where c.Citizenship_ID == citizenshipId

    select c

    The DefaultIfEmpty creates a Left Outer Join. Here's the SQL generated:

    -- Region Parameters

    DECLARE @p0 Int = 10000

    -- EndRegion

    SELECT

    [t0].[Citizenship_ID],

    [t0].[Person_ID],

    [t0].[Country_Code],

    [t0].[Is_Primary],

    [t0].[Created_By],

    [t0].[Created_Date],

    [t0].[Modified_By],

    [t0].[Modified_Date]

    FROM

    [Citizenships] AS [t0] INNER JOIN

    [Citizenship_Document_Types] AS [t1]

    ON [t0].[Country_Code] = [t1].[Country_Code] LEFT OUTER JOIN

    [Citizenship_Documents] AS [t2]

    ON ([t2].[Citizenship_Id] = [t0].[Citizenship_ID]) AND

    ([t1].[Citizenship_Document_Type_Id] = [t2].[Citizenship_Document_Type_Id]) LEFT OUTER JOIN

    [Issuing_Authorities] AS [t3]

    ON [t2].[Issuing_Authority_Id] = ([t3].[Issuing_Authority_Id])

    WHERE

    [t0].[Citizenship_ID] = @p0

    LinqPad[/url] is a great tool for learning how to work with Linq.

  • Thanks Jack.

    Although it might take awhile for me to think that is easier.:-)

    The presenter didn't know about this, although this was a few years ago.

    So things are improving - or at least some have taken the time to figure out some ways around earlier limitations.

    Greg E

  • Thanks, guys.

    Jack, to answer your question:

    So are you talking general Linq or Linq to SQL?

    I'm talking more general LINQ, but to be more specific, LINQ to Entity Framework. One of the things that keeps throwing me is that I'm finding links (no pun intended) to both LINQ to Entity and LINQ to SQL, and because the syntax is so similar, I'm having trouble following examples when going between them. That's part of my frustration with trying to learn this thing.

    LINQPad definitely looks interesting, from what little I've skimmed so far. I'll take a look at it.

    Thanks again for your help!

    +--------------------------------------------------------------------------------------+
    Check out my blog at https://pianorayk.wordpress.com/

  • Greg Edwards-268690 (10/13/2010)


    Thanks Jack.

    Although it might take awhile for me to think that is easier.:-)

    The presenter didn't know about this, although this was a few years ago.

    So things are improving - or at least some have taken the time to figure out some ways around earlier limitations.

    Greg E

    Took me a few hours to find an example of an outer join that worked.

  • Ray K (10/13/2010)


    Thanks, guys.

    Jack, to answer your question:

    So are you talking general Linq or Linq to SQL?

    I'm talking more general LINQ, but to be more specific, LINQ to Entity Framework. One of the things that keeps throwing me is that I'm finding links (no pun intended) to both LINQ to Entity and LINQ to SQL, and because the syntax is so similar, I'm having trouble following examples when going between them. That's part of my frustration with trying to learn this thing.

    LINQPad definitely looks interesting, from what little I've skimmed so far. I'll take a look at it.

    Thanks again for your help!

    Based on the little I've done with EF, I'm going to assume you are using EF 4, I'd avoid the Linq to EF stuff and use the native EF stuff.

    Linq syntax is pretty similar across all implementations. I LOVE standard Linq and lambda expressions, but not a big dan of Linq to SQL.

    Julie Lerman is an EF expert, here's her webiste, http://thedatafarm.com/main.aspx

  • Greg Edwards-268690 (10/13/2010)


    Although it might take awhile for me to think that is easier.

    Tell me about it! I told my boss that, had this been my decision, I would've done this project in ASP.NET WebForms, although I definitely understand why we went the MVC route. MVC is supposed to make things easier. But I've been working with structured programming and OOP for so long that it's hard to shift with the paradigm!

    +--------------------------------------------------------------------------------------+
    Check out my blog at https://pianorayk.wordpress.com/

  • Jack Corbett (10/13/2010)


    Ray K (10/13/2010)


    Thanks, guys.

    Jack, to answer your question:

    So are you talking general Linq or Linq to SQL?

    I'm talking more general LINQ, but to be more specific, LINQ to Entity Framework. One of the things that keeps throwing me is that I'm finding links (no pun intended) to both LINQ to Entity and LINQ to SQL, and because the syntax is so similar, I'm having trouble following examples when going between them. That's part of my frustration with trying to learn this thing.

    LINQPad definitely looks interesting, from what little I've skimmed so far. I'll take a look at it.

    Thanks again for your help!

    Based on the little I've done with EF, I'm going to assume you are using EF 4, I'd avoid the Linq to EF stuff and use the native EF stuff.

    Linq syntax is pretty similar across all implementations. I LOVE standard Linq and lambda expressions, but not a big dan of Linq to SQL.

    Julie Lerman is an EF expert, here's her webiste, http://thedatafarm.com/main.aspx

    Thanks again, Jack, for your help (as usual).

    I've already downloaded Julie's book. I'll definitely be referring to it more.

    FWIW, I have no idea what version of EF I'm running! (If it helps, I'm running VS2010 and .NET 4.0.)

    +--------------------------------------------------------------------------------------+
    Check out my blog at https://pianorayk.wordpress.com/

  • Ray K (10/13/2010)


    Jack Corbett (10/13/2010)


    Ray K (10/13/2010)


    Thanks, guys.

    Jack, to answer your question:

    So are you talking general Linq or Linq to SQL?

    I'm talking more general LINQ, but to be more specific, LINQ to Entity Framework. One of the things that keeps throwing me is that I'm finding links (no pun intended) to both LINQ to Entity and LINQ to SQL, and because the syntax is so similar, I'm having trouble following examples when going between them. That's part of my frustration with trying to learn this thing.

    LINQPad definitely looks interesting, from what little I've skimmed so far. I'll take a look at it.

    Thanks again for your help!

    Based on the little I've done with EF, I'm going to assume you are using EF 4, I'd avoid the Linq to EF stuff and use the native EF stuff.

    Linq syntax is pretty similar across all implementations. I LOVE standard Linq and lambda expressions, but not a big dan of Linq to SQL.

    Julie Lerman is an EF expert, here's her webiste, http://thedatafarm.com/main.aspx

    Thanks again, Jack, for your help (as usual).

    I've already downloaded Julie's book. I'll definitely be referring to it more.

    FWIW, I have no idea what version of EF I'm running! (If it helps, I'm running VS2010 and .NET 4.0.)

    If you are running .NET 4 then you are using EF 4. Much better than 3.5 as far as generated SQL goes.

  • vs2010 and 4.0 framework should be the latest.

    Some of these technologies change so quickly it is hard to adapt.

    My fear is jump in too early, and you may get stranded by something new.

    And then you can end up with a lot of rework adapting to something else.

    It would be nice to have the training on the platform before someone pushes you into a project and dictates how to do it.

    Hope they give you a bit of time to learn it and don't schedule like you're already adept in it.

    Greg E

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply