Page 1 of 1

Error creating DataContext

Posted: Wed 14 Sep 2011 17:06
by SomeDeveloper
I'm getting an error creating a data context instance. This started happening after I changed a column to Nullable = FALSE and updated the database from the model.

Can you please help? If needed I can send the project via email.

Error: InvalidOperationException("You should use the constructor with XmlMappingSource parameter");

Database: SQLite
.NET: 4.0, C#
VS Version: 2010 SP1
Entity Developer Version: 4.0.3

Posted: Thu 15 Sep 2011 14:04
by StanislavK
This exception specifies that the 'File' mapping mode is set for the model, and no mapping source was passed to the data context constructor.

To resolve this, you can do either of the following:
1. Set the mapping mode to 'Attributes' and save the model (so that the code is re-generated).
2. If you do use the file mapping (e.g., you have to if you are working with POCO classes), create the XmlMappingSource object from the special .xml file generated by Entity Developer:

Code: Select all

XmlMappingSource mappingSource =
  XmlMappingSource.FromUrl("..\..\[YourDataContext].xml");
var context = new [YourDataContext](mappingSource);
Please tell us if this helps.