3

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?

sth
  • 222,467
  • 53
  • 283
  • 367
Naseem
  • 41
  • 1
  • 5

1 Answers1

0

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.

wizulus
  • 5,653
  • 2
  • 23
  • 40