Reputation: 1864
I'm using EF 4.2 (database-first) with the DBContext T4 templates to create my POCO classes. This works very well, but now I stumpled over an issue with an abstract base class:
I need my T4 generated POCO class to inherit from a custom abstract class that has abstract properties:
//my abstract base class (shortened)
public abstract class BaseClass {
public abstract int? Property1 { get; set; }
public abstract int? Property2 { get; set; }
// a lot of methods that work with above properties
}
//my T4 generated entity (shortened)
public partial class Entity {
public Nullable<int> Property1 { get; set; }
public Nullable<int> Property2 { get; set; }
}
//and a partial class to make the T4 entity inherit from my abstract class
public partial class Entity : BaseClass {
}
My problem is that the compiler won't build this, because the properties in the T4 class are not marked as "override". LINQ 2 SQL had the option to change the inheritance modifier for an entity property, but I can't find this option in the EF Model Designer.
Is there a way to tell the EF Model Designer and the T4 templates to mark certain properties as override (I could, of course, change the generated C# code, but this changes would be overwritten when T4 runs again)? Is there any other way I can make this compile & work?
Thanks a lot, ~ saxx
Update 1: Fixed a typo.
Upvotes: 1
Views: 1666
Reputation: 15130
EF Model Designer offers no option to change the inheritence modifier. There are a few workarounds though.
Upvotes: 2