I have to store relational data (text, numbers and pictures) into an XML file. I want to maintain the relationship between data and the tables structure.
How do I go about doing that?
My Windows Mobile application use Windows Communication Foundation (WCF) to get data. Once it gets the data it stores them into an XML file.
The WCF use ADO.NET Entity Framework to data retrieve.
I'm going to use SQL Server 2008.
The data will be use to show it on application. I don't want to use SQL Server CE to store data because it's slower. Maybe, instead of using XML file I can use text plain files to store texts and numbers, and image files to store images.
In short, XML will be a way to store the data instead using SQL Server CE or WCF.
Thank you!
Thanks for the additional detail.
My suggestion is first, try SQL Server CE. It might not actually be slower for what you're doing. The time you save in not reinventing the wheel might be better spent in speeding up other parts of your application.
For the rest, assuming you don't need to store the data for long, nor do much with it, I'd suggest copying the data from the Web Service return type into a DataSet. The DataSet type has a WriteXml method that can save the data, and a ReadXml method that can read it back in.
While it's a little ambiguous what is needed, you can try looking into 'FOR XML EXPLICIT' under SQL Server. This will include relationships. Link: http://www.eggheadcafe.com/articles/20030804.asp
what about a dataset ? define the tables and relations, load the data into the dataset, and save it as XML (WriteXml method)
Define your XML format as an XSD. If you use Visual Studio use add new DataSet and the "custom tool" will automagically create a strong-typed set of classes based on DataSet. You can define tables and relations with constraints. It is easy to do in Visual Studio. If you are Visual Studio averse, you can create the XSD by hand and use xsd.exe to generate your code.
Once you have the strong-typed DataSet filled with data you can serialize it to an XML stream by calling WriteXml.
What do you mean by, "maintain the relationship between data and the tables structure"? Are you talking about more than maintaining the ID of a source database record in an attribute of an XML node? What do you need to do with the XML data once you have it? Will it be edited and have to be re-applied to the database?
More questions than answers from me....sorry.
What SQL Server are you using? Some servers allow you to request an XML response for a query. That could save you a lot of work.
EDIT: Since you have specified that you will use MSSQL 2008, you may be in luck. In MSSQL 2005 and later there is a "FOR XML" keyword which allows you to get results as XML. Give it a try.
Related
I'm working on an application which was previously developed with EF, SQL Server, C# and WinForms. For some reasons we need to remove SQL Server and use some and put data in some other container like XML, Excel sheet or in memory classes.
DAL was designed using EF with repository and UOW pattern. Can you please suggest me what can be the best way to migrate and what format will be easy to transfer data?
Since the data access is decoupled into a repository you should be able to write a new repository instance that will allow you to retrieve your data in its new format. Specifically if you wanted to hold the data in XML you could just write a new repository that uses Linq-to-XML to retrieve your data.
I don't know of a good quick way to transfer your data from SQL Server into XML. If I were doing it I'd probably write some custom application to make the conversion, but I suspect there are better solutions out there for this type of migration.
Your question duplicates this questions:
Entity Framework with XML Files
How to use Entity Framework 4.0 with Xml or in-memory Storage (non-SQL)
There seems to be a provider for virtuoso xml:
http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VirtAdoNet35Provider
Some hints can be found here:
http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/6f6164f6-fced-43de-b3fc-eccbd74dd482
http://blogs.msdn.com/b/adonet/archive/2009/11/05/model-first-with-the-entity-framework-4.aspx
http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework
EF ist basically developed for database abstraction. You will need to write your own xml database provider if you try to strore XML instead.
Your options are:
move to SQL compact (but not in XML)
use XPath and rewrite your code
use Xpath for your own database provider
Be aware that your xml file size and speed depends on the amount of data! Using multiple xml files can end up in a mess.
I will be using GridViews in my application and other data containers but I do not want to use MSSQL or anything like that as it is a simple program.. Can I store the data in someway in the project itself? as my data souce? Like for instance I can have a class called Employee and I want to store the employee information (data) somewhere within the project and then be able to grab it anytime i want.. without the need of using MSSQL or any database system. Is there something like this?
You can try SQL compact edition, See http://weblogs.asp.net/scottgu/archive/2011/01/11/vs-2010-sp1-and-sql-ce.aspx
I'd consider either XML files, or sql compact edition (which is similar, but not the same as SQL server) - both are very easy to use for small amounts of data. SQL CE just requires a couple of DLL's if I remember correctly (and its free)
Flat files, or XML for more structured data are probably the best bets.
Here's our situation.
We're receiving a dump of relational data in Access 2007 format. There are quite a few tables involved. We're writing a console app in c# to run various queries against this data. We only need read-only access - we're not updating the Access database.
I haven't used Access in a project since pre-Linq days, and I'm hoping we don't have to go back to coding strings of sql against an ADO.Net connection just because the database is Access. I gather Linq 2 Sql is out of the question, but might Entity Framework be usable?
How would you approach this problem?
EDIT: The console app will be dropped by a business analyst into a folder containing the Access database, and when run will generate a text file created by querying the data. So unfortunately it's not an option to transfer the data to Sql beforehand!
If you must keep the data into Access, you can pull it into a Dataset via ADO.NET, and then use the LINQ extension methods that work against a Dataset to work against the data.
It's not nearly as nice as working with SQL Server, but it does work.
I would fully import the data into Sql Server, after which I would gleefully destroy all copies of the original Access file. Then you could get as Linq-y as you like.
Linq2Sql no, LinqXml yes! How hard would it be to dump the access file to xml?
I'm not sure I understand the question, but have you considered a SQL Server linked server to the Access file? You could then use SQL Server to do the manipulation. I don't know what the limitations/pitfalls of that are, but it's a solution often suggested when there's no good direct way to manipulate the Jet/ACE database.
Hi I have a pretty complex schema (.xsd) and an .xml files. Some nodes have about 70 attributes and some 10-15. I used xsd2code to create c# classes and then deserialized my xml file. I created a database based on my .xsd class using xsd2db application. So I've read my xml file and need to store it into the database. I have 74 classes/tables with primary/foreign key relationships. I looked into SqlBulkCopy - for that it looks like I need to convert everything into datatables/rows/columns. And I will need to take into account the hierarchy for satisfying foreign keys. Is there another way of doing it? What would be the best (fastest) approach?
Thank you
Jenny
There are different ways to import a XML file either through T-SQL, SSIS, VB Script, etc.
Sorry to just google and post links, but I think sql squirrel has found the easiest method for getting an XML file into SQL Server 2005 is to use T-SQL:
http://www.lockergnome.com/sqlsquirrel/2008/05/22/how-to-import-a-xml-file-into-sql-server-2005/
http://www.lockergnome.com/sqlsquirrel/2008/05/23/how-to-turn-imported-xml-into-a-relational-format-in-sql-server-2005/
The SQLTeam seem to think T-SQL is the WTG as well:
http://weblogs.sqlteam.com/mladenp/archive/2007/06/18/60235.aspx
I have an application that needs to map relational database to XML.
The issue is that the database structure is given (I cannot change it) and the XML Schema is given (comes from WSDL).
I need to let the user of my application to tell the system that a given column in a table is mapped to a given element in the schema. Then my application needs to crate XMLs based on the database data.
Is there a technology that can help me? is there a C# control for that.
Thanks
XSLT.
I think you should dynamically (based on user input) create xslt and transform data from database (dataset?) to xml.
What's your database - SQL Server? You can achieve a lot of XML flexibility with the SELECT .... FOR XML statement in SQL Server (most definitely in 2005 and up).
And if that's not flexible enough, then I'd second "peeles" recommendation - do a SELECT...FOR XML first and transform the output using XSLT.
Marc
Select...For sounds simpler; but LINQ in your C# is probably another option.