使用 Visual Studio 类型数据集的技巧?
在 Visual Studio 2005/2008 中使用强类型数据集时,如果基础数据库架构发生更改,刷新的唯一实用方法是删除数据集并从头开始重新创建。 除非我需要自定义数据集,否则这是可以的。
通过扩展部分数据集类进行定制允许保留定制,但简单的 FillBy() 又会变成一长串 SQL。
有没有办法在不丢失数据集自定义的情况下将数据集与数据库架构重新同步?
When using strongly typed dataSets in Visual Studio 2005/2008, if the underlying database schema changes, the only practical way to refresh is to delete the dataset and recreate it from scratch. This is OK unless I need to customize the dataset.
Customizing by extending the partial dataset class allows customizations to be retained, but then a simple FillBy() again becomes a long sequence of SQL.
Is there any way to resynchronize a dataset with the database schema without losing dataset customizations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于类型化数据集使用生成的嵌套类,因此自定义设置通常会丢失。 我所做的是生成类型化数据集,然后将几个类标记为部分类。 然后,我创建包含重复嵌套类结构(也标记为部分)的单独文件。
这样我就可以重新生成我的数据集,而我要做的唯一更新就是返回并再次使它们部分化。 我的自定义保存在单独的文件中。
Because typed datasets use generated nested classes, customizations will often be lost. What I do is generate the typed dataset, and then mark several classes as partial. Then I create separate files containing a duplicate nested class structure (also marked partial).
This way I can regenerate my data set and the only update I have to do is to go back and make them partial again. My customizations are kept in separate files.
如果您只是进行简单的更改,例如向表中添加字段,那么我右键单击表并单击配置。 再次通过向导添加新字段(或者甚至用 select * 替换 select),它将字段添加到表中并同步您构建的所有查询。 我有大约 10 个不同的自定义查询的表,当我重新配置表时,所有查询都正确更新。
If you are just making a simple change like adding a field to a table, then I right click on the table and click configure. Go through the wizard again adding the new field, (or even replacing the select with select *) and it adds the field to the table and syncs up all the queries that you've built. I've had tables with about 10 different custom queries and when I reconfigure the table the queries all updated properly.
类型化数据集是邪恶的。 LINQ to SQL 应该是类型化数据集,所以我喜欢将其视为类型化数据集 3.0。 我希望当他们将 L2S 合并到实体框架中时,他们能够保留 L2S 的优点。
Typed Datasets are evil. LINQ to SQL is what typed datasets should have been, so I like to think of it as Typed Datasets 3.0. I hope when they fold L2S into the Entity Framework they retain what makes L2S so good.
我在许多 Web 和 Windows 项目中非常成功地使用了类型化数据集。
一开始有一些发现 - 学习数据集设计器的所有怪癖以及如何扩展数据集以提供更灵活的连接配置。
但是一旦你克服了这一点,生成数据访问层将是快速的工作。
I've been using typed datasets quite successfully in a number of web and windows projects.
There was a bit of discovery in the beginning - learning all the quirks of the dataset designer and how to extend the dataset to provide more flexible connection configurations.
But once you get past that, generating a data access layer will be quick work.