Linq to sql as object data source - designer problem with partial classes
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 shoul开发者_JAVA百科d 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
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.
精彩评论