I have a Foo
entity in Entity Framework. But I\'m making it inherit from IFoo
so that my business logic only knows IFoo
- thus abstracting
Use a partial class to seperate your logic and rules from the autogenerated EF objects. In the example below FooEntityObject class is split into two using the partial keyword. I've used this technique before with EF and LINQ to SQL. The partial classes can be stored in seperate files so if your regenerate your EF object again your custom code doesn't get overwriten.
interface IFoo
{
public ICollection GetBars();
}
public partial class FooEntityObject : IFoo
{
public ICollection GetBars()
{
// convert EntityCollection into ICollection here
}
}
public partial class FooEntityObject
{
EntityCollection Bars{get;set;}
}