强类型数据集和架构更改
我有一个使用强类型数据集的项目。
假设我想要更改此应用程序使用的数据库的数据库架构。 我有一个名为 Country 的表,我想添加一个名为“IsADemocracy”(这是一个示例)的 SQL Server 数据类型 BIT 的新列。
现在,如何更新强类型数据集以便可以在应用程序中使用这个新字段?
我尝试在数据集的“国家/地区”表中添加列,为其指定布尔类型并将其“源”属性映射到“IsADemocracy”。
我可以访问应用程序中的字段,为其赋予值等,但表适配器进行的基础查询尚未更新以反映此更改。它们与我在强类型数据集中添加此列之前一样。 我希望我所做的就足够了,但事实似乎并非如此。
我应该以某种方式重新生成强数据集类吗?如果是这样,有何影响?
我可能可以删除数据集设计器中的国家/地区表,然后从服务器资源管理器中重新删除它,但我有客户查询,我不想丢失它们。
谢谢。
I have a project which uses strongly typed datasets.
Let's assume I want to change the database schema of the database used by this application.
I have a table named Country and I want to add a new column named "IsADemocracy" (that's an example) of the SQL Server datatype BIT.
Now, how do I update the strongly typed dataset so that I can use this new field in the application?
I've tried adding the column in the Country table on the dataset, gave it the type of boolean and mapped its "Source" property to "IsADemocracy".
I can access the field in the application, give it a value, etc, but the underlying queries made by the table adapter have not been updated to reflect this change. They are as they were before I added this column in the strongly typed dataset.
I hoped what I did would be enough but it does not seem to be the case.
Should I regenerate the strongly datasets classes somehow? If so, how and what are the implications?
I could probably delete the Country table in the Dataset designer, and redrop it from the Server Explorer, but I have customer queries on it and I don't want to lose them.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
另一个建议 - 右键单击设计器中表的表示形式,即 xsd,然后使用“添加选项”来添加列。获得该列后,您需要设置其属性,因为默认情况下新列会作为字符串添加。这样做意味着您保留之前添加的任何自定义查询等。
这允许您添加列,显然删除更简单。
Another suggestion - right click on the Table's representation in the designer i.e the xsd, and use the Add Option, to add a Column. Once you have the column, you need to set its properties as by default a new column gets added as a string. Doing it this way means you retain any custom queries etc that have been added earlier.
This allows you to add columns, obviously deleting is more straightforward.
首先,确保您有备份
右键单击“解决方案资源管理器”中的 .xsd 节点,然后选择“运行自定义工具”
但要小心自定义查询。它们往往会在没有任何警告的情况下消失。并非总是如此。
这是从部分类“主”文件中填写这些查询的一个很好的理由。
First, make sure you have a backup
Right click on the .xsd node in Solution Explorer and select "Run Custom tool"
But be careful with your Custom Queries. They have a tendency to disappear without warning. Not always.
This is one good reason to fill in those queries form the partial class 'main' file.