How do I set EF to use an SQL datatype of XML for an object? Moreover, how does one create SQL computed columns.
We store alot of dynamic data that some folks cause meta data per row/record, it isn't standard and therefore we rely upon the xml data structure and then use computed columns to create so keys that we may use for faster SQL searches.
Quite frankly - an expando object mapping to an xml column would really float our boat.
Thanks in advance.
A data type within an XML document is a type that has been assigned to an element on the instance using the dt:dt attribute, or through an XML Schema, a formal definition of an XML document. In addition, data types can be declared as elements. The XML parser uses the data type information to validate the document.
The W3C XML Schema Datatype Specification defines numerous datatypes for validating the element content and the attribute value. These datatypes can be used to validate only the scalar content of elements, and not the non-scalar or mixed content.
SQL is good tabular data -- data that easily fits into rows & columns. XML is good for hierarchical data -- data which has several levels of different sizes. SQL is good for storage & searching. XML is good for transmitting & formatting.
xml. It is formatted with tags like HTML tags and other XML-based file types include EDS, FDX, and DAE files. An XML file acts as a database to store the data. The most commonly used example of an XML-based file is RSS Feed.
The original question was:
How do I set EF to use an SQL datatype of XML for an object?
In code first, you can do it like this:
[Column(TypeName="xml")]
public string Foo {get; set;}
Or through the fluent api:
modelBuilder.Entity<MyEntity>()
.Property(x => x.Foo)
.HasColumnType("xml");
You still need to interpret the property as a string and you're on your own for converting it to xml within C#. But this way it will get generated as an xml column and you can still perform direct sql queries against it using sql's xml functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With