开发者

How to create a class in a dbml file dynamically

I'm using linq to sql and I need to have a class in the dbml file where some of its properties are created dynamically. Is there a way 开发者_开发百科to have a class in a dbml file with some predefined properties and some dynamic properties?

Or is there any way to create a class in a dbml file dynamically?


Absolutely! Every class generated by LINQ to SQL is marked partial. That means you can add to the class in a separate file, as long as you name it correctly.

Generated File:

namespace MyApp 
{
    public partial class MyDataContext : System.Data.Linq.DataContext
    {
       // Generated Code
    }
}

Your file

namespace MyApp 
{
    public partial class MyDataContext
    {
       public string MyProperty { get; set; }
    }
}

This works with the DataContext class, Table classes, and Stored Procedure response classes, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜