c# - Export/Import subset of data from SQL-Server -


as feature our application, looking find best way export subset of related data database sql-server 2008 express database out disk. exported content required imported keeping identities database , server.

i have medium sized data model of 143 tables, on use entity framework 3.5 data access in our applications. model want extract rows tables based on given criteria.

new c# , entity-framework, not new sql-server, i've taken on project developer began writing toxml() methods each entity extracted (20% done). maintenance nightmare. worse fromxml() entities, there complexities having unique keys etc...

i experimented select ... xml auto, xmlschema combined microsoft sqlxml bulk loading. while @ first went plain vanilla tables, ran dead-end because appears not support xml data types without schemas or @ least without deal of manual intervention. have several tables xml data type columns. there yet unknown complexities bulk-loading in general having triggers, nulls, unique keys, , contraints, , more haven't encountered yet presume.

one idea had write matching xsd schema our database (or generate one) , use xsd.exe generate class model collection of dtos. use mapping library automapper populate dtos , serialize them disk. reverse on import.

i know big , broad question, can provide guidance or ideas this? there ways can done options in entity-framework? there open-source libraries can this?

i don't know object model, possibly use xml serialization?

    public static string objecttoxml(object object)     {         if (object == null)             throw new argumentexception("object can not null");         using (memorystream stream = new memorystream())         {             xmlserializer serializer = new xmlserializer(object.gettype());             serializer.serialize(stream, object);             stream.flush();             return utf8encoding.utf8.getstring(stream.getbuffer(), 0, (int)stream.position);         }     }      public static t xmltoobject<t>(string xml)     {         if (string.isnullorempty(xml))             throw new argumentexception("xml can not null/empty");         using (memorystream stream = new memorystream(utf8encoding.utf8.getbytes(xml)))         {             xmlserializer serializer = new xmlserializer(typeof(t));             return (t)serializer.deserialize(stream);         }     } 

the main issue see xml data though (possibly wrap in cdata prior serialization?).


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -