Is it possible to generate a XML Schema of a Database programatically with .Net and C#? I want to look into NDbUnit but for big databases it would not really be feasible to make a Schema manually?
是否可以使用.Net和C#以编程方式生成数据库的XML模式?我想研究NDbUnit但是对于大型数据库来说,手动制作Schema实际上是不可行的?
3 个解决方案
#1
26
Is it possible to generate a XML Schema from a Database?
是否可以从数据库生成XML模式?
It sure is, XMLSpy can generate XML Schema from a database.
当然,XMLSpy可以从数据库生成XML Schema。
There's another way, though I've never tested it:
还有另外一种方法,虽然我从未测试过它:
create table Person
(
Age int not NULL check( Age > 0) ,
Height numeric(10,2) not NULL check( Height > 5),
Gender varchar(5) not null check( Gender in ('M', 'F', 'O')),
BirthDate datetime null,
)
DECLARE @schema xml
SET @schema = (SELECT * FROM Person FOR XML AUTO, ELEMENTS, XMLSCHEMA('PersonSchema'))
select @schema
#2
2
I could do it like this:
我可以这样做:
DataSet results = new DataSet();
SqlCommand command = new SqlCommand("SELECT * FROM table", new SqlConnection(connectionString));
SqlDataAdapter sqlAdapter = new SqlDataAdapter(command);
sqlAdapter.FillSchema(results, SchemaType.Mapped);//Fills dataset with schema from query
results.WriteXmlSchema(mySchema);
Problem is, how could I adapt this method so that it could be used with a indeterminate amount of tables? Without building up a string though concatenation which is not exactly ideal!
问题是,我如何调整这种方法,以便它可以与不确定数量的表一起使用?没有建立一个字符串虽然连接不完全理想!
#3
-1
Use MyGeneration's typed-dataset-template to auto-generate the XSD (http://www.mygenrationssoftware.com). Its free, OSS, and works great. Also, the NDbUnit team is presently working on an add-on tool to NDbUnit that will make it possible to not only extract the schema from the database, but also to edit the test data that is contained within the accompanying XML dataset. ETA for this tool is about mid-July.
使用MyGeneration的typed-dataset-template自动生成XSD(http://www.mygenrationssoftware.com)。它的免费,OSS,并且工作得很好。此外,NDbUnit团队目前正在为NDbUnit开发一个附加工具,该工具不仅可以从数据库中提取模式,还可以编辑随附的XML数据集中包含的测试数据。该工具的ETA大约在7月中旬。
#1
26
Is it possible to generate a XML Schema from a Database?
是否可以从数据库生成XML模式?
It sure is, XMLSpy can generate XML Schema from a database.
当然,XMLSpy可以从数据库生成XML Schema。
There's another way, though I've never tested it:
还有另外一种方法,虽然我从未测试过它:
create table Person
(
Age int not NULL check( Age > 0) ,
Height numeric(10,2) not NULL check( Height > 5),
Gender varchar(5) not null check( Gender in ('M', 'F', 'O')),
BirthDate datetime null,
)
DECLARE @schema xml
SET @schema = (SELECT * FROM Person FOR XML AUTO, ELEMENTS, XMLSCHEMA('PersonSchema'))
select @schema
#2
2
I could do it like this:
我可以这样做:
DataSet results = new DataSet();
SqlCommand command = new SqlCommand("SELECT * FROM table", new SqlConnection(connectionString));
SqlDataAdapter sqlAdapter = new SqlDataAdapter(command);
sqlAdapter.FillSchema(results, SchemaType.Mapped);//Fills dataset with schema from query
results.WriteXmlSchema(mySchema);
Problem is, how could I adapt this method so that it could be used with a indeterminate amount of tables? Without building up a string though concatenation which is not exactly ideal!
问题是,我如何调整这种方法,以便它可以与不确定数量的表一起使用?没有建立一个字符串虽然连接不完全理想!
#3
-1
Use MyGeneration's typed-dataset-template to auto-generate the XSD (http://www.mygenrationssoftware.com). Its free, OSS, and works great. Also, the NDbUnit team is presently working on an add-on tool to NDbUnit that will make it possible to not only extract the schema from the database, but also to edit the test data that is contained within the accompanying XML dataset. ETA for this tool is about mid-July.
使用MyGeneration的typed-dataset-template自动生成XSD(http://www.mygenrationssoftware.com)。它的免费,OSS,并且工作得很好。此外,NDbUnit团队目前正在为NDbUnit开发一个附加工具,该工具不仅可以从数据库中提取模式,还可以编辑随附的XML数据集中包含的测试数据。该工具的ETA大约在7月中旬。