Entity Framework with Xml Files

Entity Framework with XML Files

Entity Framework itself is provider-based, and is designed to operate over a relational database. If you really wanted to, you could write your own provider for EF that reads from/writes to an xml file, but it would be a huge amount of work.

I expect you should really be looking at one of:

  • LINQ-to-XML
  • XML (de)serialization
  • XPath/XQuery
  • XSLT

Entity Framework doesn't have a natural fit in this scenario.

Entity Framework Code First with XML as Data Source

You would need some XML database which is accessible through ADO.NET. Otherwise you are going to implement custom EF provider (which will be still based on ADO.NET) targeting your XML files. EF is for accessing databases.

If you want to have more "automated" way simply use XML serialization and related attributes - it will be same as using code first with data annotations.

How to map XML document to entity framework object?

Everything is said in :

Cannot serialize member
Proj.Accounting.Entity.DocumentStatus.Documents
of type

System.Collections.Generic.ICollection1[[Proj.Accounting.Entity.Document,
Proj.Accounting.Entity, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]] because it is an interface

Interface are not serializable. Transform all your ICollection properties to type HashSetto enable serialization of these items.

Is it necessary to deploy the XML file in a class library?

The XML file contains the doc comments for the public types & members in the assembly.

You only need it if you want Visual Studio to show documentation in IntelliSense.

If you're deploying a consumer-facing app (as opposed to a developer-facing reusable library), you do not need it.

how to move serialized xml data to a entity framework code first database?

i manage to get it working now :-)

What i did for starters, was to save the data to the database a little at a time. First the book. Then the chapters. and so on, and so on.

And i move the:

db.SaveChanges()

into the nested foreach loops, so that data got saved to the database while looping, insteed of waiting until the end. I suspect that it was just to much data to handle.



Related Topics



Leave a reply



Submit