Linq entities with providered data source.

Last post 12-20-2007 2:43 PM by jf26028. 4 replies.

Sort Posts:

  • Linq entities with providered data source.

    12-19-2007, 11:57 PM
    • Loading...
    • jf26028
    • Joined on 09-22-2005, 3:23 PM
    • Posts 3

    I am trying to get my linq hat on right, and hopefully, someone will have some insight on how to do this.

    I would like to build a data access layer for my website.  These are my requirements:

    1.  Use the Linq To Sql entities for all the model.

    2.  Support both sql server and xml as the data source via a providered interface. 

    Think .nettiers or blogengine, but using linq to sql for the sql provider, linq to xml for the xml provider, all the while having the entities generated from the dbml file, or sqlmetal.  The thing I am having a hard time with is removing the entities generated by the dbml file from the data access to enable returning the entities from both, the sql and xml providers.  I dont think that this approach is possible with linq, but I really hate to give up on it so quickly.  Anyone have any suggestions, other than something like DTOs and converting from the sql entities into some common object and having to support 3 versions of the entities in a single project?

    Jesse Foster | jf26028

     

     

    Filed under: , ,
  • Re: Linq entities with providered data source.

    12-20-2007, 1:10 AM
    • Loading...
    • marcind
    • Joined on 09-06-2007, 1:11 AM
    • Redmond, WA
    • Posts 305
    • AspNetTeam

    Hi,

    this forum is mostly for the ASP.NET 3.5 Extensions Preview. For LINQ-related questions, pleas visit this forum.

    Marcin Dobosz
    SDE, ASP.NET Team, Microsoft
    Get the Dynamic Data Futures 7/16 update.
  • Re: Linq entities with providered data source.

    12-20-2007, 1:25 AM
    • Loading...
    • marcind
    • Joined on 09-06-2007, 1:11 AM
    • Redmond, WA
    • Posts 305
    • AspNetTeam

    Sorry, I misread your question. The Linq to SQL and Linq to XML models are different (what they share in common is the LINQ part - programming language syntax for performing queries on the data) and there is no common abstraction layer on top of them.

    Marcin Dobosz
    SDE, ASP.NET Team, Microsoft
    Get the Dynamic Data Futures 7/16 update.
  • Re: Linq entities with providered data source.

    12-20-2007, 12:19 PM
    • Loading...
    • jf26028
    • Joined on 09-22-2005, 3:23 PM
    • Posts 3

    You are right, marcind.  This post should be moved.  Can someone move it for me?

    Anyway, the closest I have some is using a raw set of model classes, and in your linq to sql entities, you have to do something like this:

    private List<NorthwindTest.Model.Product> GetAllProductsFromTheDatabase()
    {
    Monkey.
    Northwind northwind = new Monkey.Northwind("connection string"); // note that Monkey.Northwind is where the northwind connection stuff is, but NorthwindTest.Model is where the entities are.

    List<NorthwindTest.Model.Product> products = (from p in northwind.Products
    select new NorthwindTest.Model.Product()
    {
    CategoryID = p.CategoryID,
    Discontinued = p.Discontinued,
    ProductID = p.ProductID,
    ProductName = p.ProductName,
    QuantityPerUnit = p.QuantityPerUnit,
    ReorderLevel = p.ReorderLevel,
    SupplierID = p.SupplierID,
    UnitPrice = p.UnitPrice,
    UnitsInStock = p.UnitsInStock,
    UnitsOnOrder = p.UnitsOnOrder
    }).ToList();

    return products;
    }

    Then, you do the same over in xml land, and it should work.  You still have a dto type situation with the same model defined in Monkey.Northwind as in NorthwindTest.Data, but there is no way to get around it, from what I can tell.  So, you can have a clean model with providers for both xml and sql server using linq as your data access, without violating DRY too much. 

    Inserts and updates, like with all of linq, are another story and Ill check those out next.

    Jesse Foster | jf26028

     

     

  • Re: Linq entities with providered data source.

    12-20-2007, 2:43 PM
    • Loading...
    • jf26028
    • Joined on 09-22-2005, 3:23 PM
    • Posts 3
Page 1 of 1 (5 items)
Microsoft Communities
Page view counter