everyone. I've got an issue with linq to sql.
I'm using attributes from System.Data.Linq.Mapping to map my classes and tables. I've noticed, that some column definitions are repeated in my code (like ID's, for example). So I'd like to move such definitions to the base class. And I've wrote something like this:
public abstract class BasicEntity
{
[Column(IsDbGenerated=true, IsPrimaryKey=true)]
public int ID { get; set; }
}
[Table(Name = "Users")]
public class User : BasicEntity
{
[Column(Name = "Name")]
public string Name { get; set; }
}
public class TestDataContext : DataContext
{
public TestDataContext(string connectionString) : base (connectionString) { }
public Table<User> Users { get { return this.GetTable<User>(); } }
}
....
{
TestDataContext context = new TestDataContext(validConnectionString);
if(context.DatabaseExists())
context.DeleteDatabase();
context.CreateDatabase(); // an exception thrown from here
}
So, when I try to create a database, I've got an System.Data.SqlClient.SqlException, that says: "Column named "ID" is not present in the targeted table or view." Well, obviously, this exception is caused by my BasicEntity.
Finally, my question is: Is there a way to inherit column definitions to remove repeated code?
And to be clear - I use #develop, which does not have fancy LINQ2SQL designer/codegenerator, like VS.
Many thanks in advance.