开发者

How to effectively save database table names in XML and parse them in C#

开发者 https://www.devze.com 2023-03-29 03:15 出处:网络
I have a requirement to copy the tables from one DB to another . The table names (to be used in the application) are configured in the XML file.

I have a requirement to copy the tables from one DB to another . The table names (to be used in the application) are configured in the XML file.

This works out 开发者_C百科if the tables doesn't have any relations. In case any of the tables have relations. What is the best way to proceed?

  1. How to decide the XML schema? (how to specify master tables, if they are in turn dependent on other tables)
  2. How to effectively parse the XML schema in C#, so that the master tables are loaded first.

Thanks, Vijay


2.How to effectively parse the XML schema in C#, so that the master tables are loaded first.

NOT AT ALL. This is a toy data set (i.e. small), just use the Xml Serializer. No need to write parser.

1.How to decide the XML schema? (how to specify master tables, if they are in turn dependent on other tables)

Experience, requrements and KISS principle. Sorry, this is so basic I dont know what else to write.


Using linq-to-sql, it is possible to have an external mapping in xml format between the classes and their properties and the table and column names they map to. Linq-to-sql have features for foreign key references etc. built in.

Using an external mapping source, you will have to do some work by hand. The basic steps are:

  1. Create the database if not already created.
  2. Write classes with the names that you want to use in the code. You could possibly use the SqlMetal tool to generate raw files that you can strip from mapping attributes.
  3. Write an xml mapping file.

If you are not familiar with linq-to-sql I would recommend you to start with a toy project using the Visual Studio Designer, to quickly get started to get familiar with the technology.

0

精彩评论

暂无评论...
验证码 换一张
取 消