locked
LINQ to Entities with an XML data source? RRS feed

  • Question

  • Apologies if this is a daft question but is it possible for LINQ to Entities to address data sources other than a relational database?  I am a beginner with LINQ and all the examples I've seen are based on the Northwind and AdventureWorks databases.  Can you use LINQ to Entities with an XML file as the underlying data source?

    What I'm hoping is to be able to use the designer to combine entities from different underlying sources (SQL, XML etc.) and address them together with LINQ to Entities.  Is this possible?

    Ed Graham
    Thursday, June 11, 2009 10:10 PM

Answers

  • Ed,

    LINQ to Entities is a "variant" (I don't know the official term) of LINQ that works with Entity Framework objects. WHat you would need to pull this off is an XML provider for the Entity Framework. At this time, I believe that the only MS provider is for SQL Server. I know there is a 3rd party provider for Oracle, and there might be an open source or 3rd party provider for XML (although I couldn't find one for you).

    However, at this point I am 99% sure that EF is UNABLE to utilize multiple providers in a single model. I do believe that this is a future feature for Microsoft. (At least I hope so. How cool would that be?)

    Hope that helps.

    (If you do come across an XML provider for EF, could you post a link here?)

    Chris

    Chris Snyder, Stumbling through code one day at a time If your question was answered, please mark it.
    • Marked as answer by Ed Graham Friday, June 12, 2009 4:01 AM
    Friday, June 12, 2009 3:54 AM

All replies

  • Ed,

    LINQ to Entities is a "variant" (I don't know the official term) of LINQ that works with Entity Framework objects. WHat you would need to pull this off is an XML provider for the Entity Framework. At this time, I believe that the only MS provider is for SQL Server. I know there is a 3rd party provider for Oracle, and there might be an open source or 3rd party provider for XML (although I couldn't find one for you).

    However, at this point I am 99% sure that EF is UNABLE to utilize multiple providers in a single model. I do believe that this is a future feature for Microsoft. (At least I hope so. How cool would that be?)

    Hope that helps.

    (If you do come across an XML provider for EF, could you post a link here?)

    Chris

    Chris Snyder, Stumbling through code one day at a time If your question was answered, please mark it.
    • Marked as answer by Ed Graham Friday, June 12, 2009 4:01 AM
    Friday, June 12, 2009 3:54 AM
  • Thanks a lot, Chris -- much appreciated.  If I learn anything to the contrary, I'll post it here.
    Friday, June 12, 2009 4:02 AM
  • Do you want Entity SQL and ObjectQuery support over XML, or just LINQ support? If you just need LINQ support, you want LINQ to XML not LINQ to Entities. You should be able to find plenty of LINQ to XML samples out there.
     
    JIm
    Monday, June 22, 2009 6:04 PM
  • Hi Jim,

    I have to admit that I don't really know what LINQ to Entities brings to the table above and beyond LINQ to SQL/XML.  I thought it might be the possibility of combining two disparate sources of data in a single model; hence my question.

    What I would really like to be able to do is use the design/code-generation tools to create objects that represent data structures from SQL and XML simultaneously.  A simplification of my application is as follows:

    Object hierarchy

    Series > Survey > Topic > Question

    SQL Database

    tblSeries, tblSurvey

    XML file

    A separate file, survey_xxx.xml, for each individual survey containing the questions in it, grouped by topic.

    That is to say, I have a SQL table with one row for each different series of surveys called tblSeries; then another table with a row for each survey called tblSurvey (with an FK relationship to tblSeries).  The data for each survey is contained in an XML file (known as a DDI file), the name of which is referred to in tblSurvey.  The DDI file holds all the question data, grouped by topic.

    I have an XSD schema for the DDI, and have used the LINQ to XSD project on CodePlex to query the DDI using strongly typed code, which is awesome.  However, I am currently reading the database information for the series and surveys separately, using LINQ to SQL, and then sticking them together manually in my code.  It would be really nice if there were a way of creating a single C# object hierarchy that could represent all my data!

    All thoughts gratefully received,

    Ed

    Tuesday, June 23, 2009 3:15 PM