I have several entites that are identical except for the class name that each are mapped to a corresponding identical table. The mapping for each table is similar to the following:
modelBuilder.Entity<Foo>().Map(x =>
{
x.MapInheritedProperties();
x.ToTable("Foo");
})
This approach works, but is repetitive.
I created this class hoping to get rid of the reposition. it is simplified here for brevity.
public class Generic<T>
{
public Generic(DbModelBuilder modelBuilder, string tableName)
{
modelBuilder.Entity<T>().Map(m =>
{
m.MapInheritedProperties();
m.ToTable(tableName);
});
}
}
I get the following compiler error that I do not understand:
The type 'T' must be a reference type in order to use it as parameter 'TEntityType' in the generic type or method 'System.Data.Entity.DbModelBuilder.Entity<TEntityType>()'
- Like many .Net coders I use generics a lot but do not write them often.
- I have use EF for a while, but I am pretty new to Code First
- I did a lot of searching on and off of SO with no luck.
- What am I doing wrong? What do I not understand?
Thanks in advance, Jim