LinqConnect supports external (XML) mapping.
You can split your entities and mapping rules with the help of this technology. A
separate XML file is used to specify mapping between database
and your object model. You can treat this file like a configuration file for your
application.
Note: |
External mapping overrides attribute-based mapping. In other words, when you use an
external mapping source to create a DataContext, it ignores all mapping attributes you have created on classes.
|
To use external mapping, one needs to create the XML mapping file. The main model file (e.g., CrmDemoContext.lqml) should not be used for this purpose, as it stores extended information about entity fields and database columns. Thus, .lqml files include properties not declared in the mapping files schema.
To create the proper file, set the 'Mapping Mode' model property to 'File'. In this case, Entity Developer will generate a mapping file (for example, CrmDemoContext.xml) that satisfies the standard schema. You can use it in the following way:
C#csharp | Copy Code |
---|
Stream contextStream = System.IO.File.OpenRead("CrmDataContext.xml");
Devart.Data.Linq.Mapping.MappingSource mappingSource =
Devart.Data.Linq.Mapping.XmlMappingSource.FromStream(contextStream);
context = new CrmDemoContext.CrmDemoDataContext(connectionString, mappingSource);
|
Visual Basic | Copy Code |
---|
Dim contextStream As Stream = System.IO.File.OpenRead("CrmDataContext.xml")
Dim mappingSource As Devart.Data.Linq.Mapping.MappingSource =
Devart.Data.Linq.Mapping.XmlMappingSource.FromStream(contextStream)
Context = New CrmDemoContext.CrmDemoDataContext(connectionString, mappingSource)
|
If this file is saved as an embedded resource of the compiled assembly, it should be used as:
C#csharp | Copy Code |
---|
Stream contextStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("CrmDataContext.xml");
Devart.Data.Linq.Mapping.MappingSource mappingSource =
Devart.Data.Linq.Mapping.XmlMappingSource.FromStream(contextStream);
CrmDemoContext.CrmDemoDataContext context
= new CrmDemoContext.CrmDemoDataContext(connectionString, mappingSource);
|
Visual Basic | Copy Code |
---|
Dim contextStream As Stream = Assembly.GetExecutingAssembly.GetManifestResourceStream("CrmDataContext.xml")
Dim mappingSource As MappingSource =
Devart.Data.Linq.Mapping.XmlMappingSource.FromStream(contextStream)
Context As New CrmDemoContext.CrmDemoDataContext(connectionString, mappingSource)
|