将 C# 类(类库)转换为 SQL DDL(表) [英] Convert C# classes (class library) to SQL DDL (tables)

查看:37
本文介绍了将 C# 类(类库)转换为 SQL DDL(表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将一组C#类(类库)转换为SQL Server使用的SQL表,这样数据才能存储在数据库中,并通过数据库进行操作.

I have to convert a set of C# classes (class library) to SQL tables to be used by SQL Server, so that the data can be stored in a database and manipulated through the database.

问题是这些类的数量很大(超过1000个类),手动设置这样的数据库模式(表、索引、存储过程等)需要很长时间——更不用说我需要维护的类层次结构.

The problem is that the number of these classes is big (more than 1000 classes), and it would take a long time to setup manually such a database schema (tables, indexes, stored procedures, etc.) - not to mention the class hierarchies that I need to maintain.

所以,问题是:

是否有工具可以帮助我从 C# 类库创建数据库架构?

Is there a tool that would help me to create a database schema from a C# class library?

我不是在寻找完美的工具(但如果有这样的工具我会很高兴知道),而是在寻找至少可以帮助我创建一个起点的工具.

I am not seeking for the perfect tool (but if there is such a tool I would be very happy to know), but for a tool that will help me at least create a starting point.

请注意,我更希望您建议的解决方案参考 .NET Framework 2.0 版,并基于传统实践(T-SQL 代码如:CREATE TABLE ...),尽管欢迎提出任何建议.

Please, also note that I would prefer your suggested solution to refer to version 2.0 of the .NET Framework, and being based on traditional practices (T-SQL code like: CREATE TABLE ...), although every suggestion is welcomed.

推荐答案

如果您可以使用 Visual Studio 2010 v4.0 框架,则有一些新功能可以使用模型优先"和实体框架生成脚本.这显然对 v2.0 没有帮助,但我认为值得一提.

If you could use Visual Studio 2010 v4.0 framework there are some new capabilities to generate scripts using "Model First" and entity framework. This isn't helpful for v2.0 obviously but I thought it was worth a mention.

模型优先"功能让您可以在实体设计器中设计概念 (CSDL) 模型,然后生成存储 (SSDL) 模型以及它们之间的映射 (MSL).此外,我们还生成 T-SQL 脚本来为您创建数据库.要运行 Model First 向导,只需右键单击实体设计器界面,然后选择从模型生成数据库...".有一篇深入的博客文章 此处.另外,检查 这篇文章出来了.

The "Model First" feature lets you design a conceptual (CSDL) model in the Entity Designer, and then generate the storage (SSDL) model, as well as the mapping (MSL) between these. In addition, we also generate T-SQL scripts to create the database for you. To run the Model First wizard, just right-click on the Entity Designer surface, and choose "Generate Database from Model...". There's an in-depth blog post here. Also, check this article out.

这篇关于将 C# 类(类库)转换为 SQL DDL(表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆