How to create a class in a dbml file dynamically

I use linq for 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 a way to create a class in a dbml file dynamically?

+3
source share
1 answer

Absolutely! Each class generated by LINQ to SQL is tagged partial. This means that you can add to a class in a separate file if 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 classes, the Table class and the stored procedure classes, etc.

0
source

Source: https://habr.com/ru/post/1746103/


All Articles