How to use linq as a ORM mapper? RRS feed

  • Question

  • Hi

    I've been designing a couple of application using NHibernate and now looking into linq. I must mention that I am doing this at my spare time, I am not a proffessional developer, nor is my command over the english language.


    The way I've been using NHibernate as an translator between my business objects and the data tables in the database.

    Basically it can be seen in this example..


    class A


    public string C;

    public string D;

    public IList<B> E;




    class B


    public string A;

    public string C;



    It takes some plumbing to make things work,, but it works well.


    Can you do the same using linq???


    Most of the examples I found on the internet, uses the Northwind database example. I seems to mee that the examples more or less maps the data base tables to each other using relations based in database keys. For an example, the always used order, ordetdetail example. It is often illustrade with a OrderDetail Class, containing a integer as a Order reference.


    Refereing to my example above, I would have renamed class A to "class Order",,, and class B to "class OrderDetail".


    Am I completly out of order here Smile

    Greatful for any comments.









    Wednesday, November 28, 2007 7:59 PM


  • There are currently two ORMs that you can use with LINQ: LINQ to SQL and ADO.NET's LINQ to Entities.  LINQ to SQL has been released as part of Framework 3.5; LINQ to Entities will be released later next year as a separate shipment.

    With LINQ to SQL, you can map classes to tables either with attributes or an XML file.  Visual Studio 2008 creates mapped table classes for you automatically, as will the SqlMetal command-line utility.  In your example, you'd replace

    public IList<B> E;


    public EntitySet<B> E;

    Scott Guthrie's blog is a good place to start for information on using LINQ to SQL.


    Wednesday, November 28, 2007 10:56 PM