I have a simple class:
public class TestClass<T> {
public int ID { get; set; }
public T Value { get; set; }
}
Is is possible to use EF Code First and Repository pattern to save this kind of elements to SQL database?
Edit: It seems like the DbSet's cannot be created using the -notation. E.g.
public class UnitOFWorkTestContext : DbContext {
...
public DbSet<TestClass<int>> TestClass_Int { get; set; }
...
}
Gives error:
The type 'UnitOFWorkTest.Models.TestClass`1[System.Int32]' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject.
Below is the copy of my own working code. I do not pretending that my code is perfect, but it is handy and has loose coupleness. Also, it will be quite big amount of code, but do not be afraid =)...
IEntity:
AbstractRepository and interface:
Concrete repository:
DbContext successor:
Unit of work:
Usage:
I think this link may be helpful for u
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application