linq2db / docs

Documentation sources and build scripts
2 stars 10 forks source link

Load Entity-DB mapping and Entity attributes from XML file (vs. POCO attributes) #16

Open marcguyboyer opened 8 years ago

marcguyboyer commented 8 years ago

Hi Igor,

I am preparing to use linq2db in a project. The Wiki gives an example of how to annotate a POCO class to build the Entity-DB mapping necessary to generate usable SQL for LINQ expression tree. However, I would like to load these attributes from an XML file instead - to avoid mixing DB and Entity specification. This will leave the POCO code clean. But linq2db will still have what it needs to do the SQL generation.

LinqToDB.Metadata.XmlAttributeReader looks like it will fit the bill, and there is sample XML in the Tests.Metada.XmlReaderTests.cs file. However, I'm not confident that I could write up XML that would work first-time with linq2db. I am also not certain how to apply the loaded mapping so that linq2db uses it (instead of trying to use reflection to analyse the POCO types).

Would you have a minute to post: a) a sample XML file that shows the key attributes that might be applied to a POCO class and its members; b) how to initialize linq2db so that this model is used, and not the one generated by reflection - which won't work if I don't annotate the POCO class with the various attributes.

I did notice that you also have a tool to generate the annotated POCO classes from a model (DB or otherwise). However, again, my hope is to keep the entity-DB mapping and entity attributes in an XML file, to keep the POCO sparse. Thank you!

Marc