Linq to sql 作为对象数据源 - 部分类的设计器问题
我在 Visual Studio 2008 中创建了一个简单的 LINQ to Sql 类项 (DataClasses1.dbml)。我可以在那里看到三个文件:“.layout”文件、“.cs”文件和“.designer.cs”文件。
接下来,我将 DataGridView 添加到 Windows 窗体,并从 LINQ To SQL 文件中选择一个包含一个表的新对象数据源。到目前为止一切正常。
当我想向自动生成的实体类之一添加新属性时,问题就开始了。所有类都声明为“部分”,因此理论上我应该能够使用新属性将代码写入“DataClasses1.cs”文件。当我这样做时,我可以在代码中看到新属性(智能感知有效),但设计器无法识别它(例如,当我在 datagridview 中选择列时,它不会出现在可用字段列表中)。但是当我将新属性移动到“DataClasses1.designer.cs”文件时,一切正常。我不想将我的代码放在设计器文件中,因为它是自动生成的并且可以自动覆盖。
我该怎么做才能使 Windows 窗体设计器识别添加到与 Designer.cs 不同的文件中的属性?
提前致谢
I have created a simple LINQ to Sql class item in Visual Studio 2008 (DataClasses1.dbml). I can see three files there: ".layout" file, ".cs" file and ".designer.cs" file.
Next I have added a DataGridView to a Windows Form and selected a new Object Data Source with one table from my LINQ To SQL file. So far everything works OK.
Problem starts when I want to add a new property to one of my auto-generated entity classes. All the classes declared as "partial", so theoretically I should be able to write code to the "DataClasses1.cs" file with my new property. When I do it I can see the new property in my code (Intellisense works) but the designer doesn't recognize it (for example when i select columns in the datagridview it doesn't appear on the list of available fields). But when I move the new property to the "DataClasses1.designer.cs" file everything works fine. I do not want to place my code in designer file as it is autogenerated and can be overwritten autmatically.
What can I do to make the Windows Forms designer recognize properties added to files different than designer.cs ?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
r单击 dbml 并选择查看代码 (F7)。这将在同一“组”内创建一个代码文件 DataClasses1.cs(如果尚不存在)。该文件包含一个部分类,并且永远不会自动生成。您可以将代码放在那里。
rclick on dbml and choose View Code (F7). This will create a code file DataClasses1.cs (if its not there already) within the same "group". This file contains a partial class and will never be auto-generated. You can place your code there.