EntityFramework and XML - c#

We have a application that is making requests to a MSSQL DB via Entity Framework. One column in one table is a serialized C# class, stored in XML format. We would like to perform simple XPath queries against this data from C#. Currently we simply load the dataset, parse the XML via linq-to-XML then query the structure. This is of course the absolute worst way to solve this problem, so I'm looking for alternatives.
MS SQL 2008 can query XML data, so how do I do that through EF?

You can use a stored procedure. Or you can run dynamic SQL using ObjectQuery. Other than that, I don't know of any way to use the XML features of SQL Server through EF.

Related

dump XML into MySQL

I've got a database dump in XML coming from some Windows application. I believe its SQL Server 2008 data dumped into XML via C#, although I do not have access to the source. I only have the dump.
The XML file matches this format:
MSDN DataTable::WriteXmlSchema
Is there a known / convenient way to import this into MySQL? Is there anything in VisualStudio or MySQL Workbench that might help?
MySQL (as of version 5.5) has a LOAD XML syntax, see this link: https://dev.mysql.com/doc/refman/5.5/en/load-xml.html
If your data doesn't fit that schema, you might be able to transform it into that schema.
Otherwise, you could use the ODBC .NET Managed Provider to talk to MySQL from C# (http://support.microsoft.com/kb/310988), although I don't know whether it has been tested, or whether it is supported for MySQL.
From there you could parse the XML and create insert statements, etc.
Or, if you can't get the ODBC provider working, you could write a program to parse the XML, and write the appropriate SQL statements to insert all the data.
In short, you get to have fun with this.

Which ORM can query XML in the database

I am planning to store XML in the database and looking for an ORM that can easily query values in the database. I will be using SQL Server 2008 or MySQL depending on the XML support. Can you give your thoughts or advice on which tool is best for this.
Linq to SQL can do so... see this

How to store XML files in SQL database using C#?

I have an XML file which should be a part of a table in my SQL database (say, name, data and XML).
I prefer not to make a string of it if possible.
What column type should I use for it? I chose XML but I'm not sure how to work with it.
A small code example would be very appreciated.
Thanks.
SQL Server (if you're using it) has an XML datatype which you can use. I've never used the datatype but we covered it during an SQL Server/.NET course at university.
http://msdn.microsoft.com/en-us/library/ms189887.aspx

How can I easily store my C# data structure(XML serialiazable) into a database?

I have a C# data structure which consists of classes and collections which have references to each other. Currently I am using Serialization to store the structure in XML, which works as a handy way to save/load the structure into my application.
If I want to be able to save/load the structure into a database, is there a simple way? Should I use LINQ?
Just to be 100% clear LINQ has nothing to do with storing data in a database. LINQ is a language query for c# with syntax that resembles SQL.
So in order to answer your question you could look at the Entity Framework (I'd recommend this if you are using .NET 4.0) or LINQ to SQL
It currently depends on your needs, and the db engine you are using:
If you need to perform queries against the XML contents you can use a XML field (mssql and oracle do support them).
If you only need to store/retrieve it, just store it in a long string field (NText in sqlserver. NCLob in Oracle).
Have you tried NHibernate?
EDIT: I don't know if this would be ok for you, but if you can define DB tables to hold your data structures, you could have code auto-generated using LINQ to SQL. Check ScottGu's tutorial on LINQ to SQL. If your data structures are not changing too often this could be a good way to go.

Convert a c# mdb solution to xml?

I have a system that uses an mdb database with an xsd descriptor written in c#. Now I want to use one or more xml files with the same data instead. I have generated a couple of adapters for the mdb, but now I don't know what is needed for using xml instead. Anyone have some tips? I have managed to save the mdb as a few xml files.
Very unclear, XML is a very poor substitute for a database. I reckon you'll want to use DataTable or DataSet to load the .mdb data. Their WriteXml() method makes it very easy to generate the xml.
The XML is not fully substitute for relation database. The dataadapters are not supposed to work with XML files and the SQL language too. I recommend you choose another SQL database (you need propably some embeded database - such as Firebird, PostreSQL, SQLite, MSSQL CE, etc...). You can still use a OLE DB data providers (DataAdapters, DataReaders, etc...) and the data layer will need only little change because of SQL dialects.
However, if you need the data in XML, you need change whole data access layer.

Categories

Resources