I'm using the Microsoft.Data.Entity.CTP (in the Entity Framework CTP) under the .NET 4 framework to create the EDMX metadata from my C# classes to create a database schema.
I setup a simple model as such:
public class AModelContainer : ObjectContext
{
public IObjectSet<RegularClass> RegularClasses {
get { return CreateObjectSet<RegularClass>(); }
}
}
I follow the simple pattern of defining a new ContextBuilder based on my model.
var builder = new ContextBuilder<AModelContainer>();
using(var context = builder.Create(new SqlConnection(connString)))
{
context.RegularClasses.AddObject(new RegularClass());
context.SaveChanges();
}
This works fine. Until I try to do something a little more complex...
I extend my model with a generic class
public class AModelContainer : ObjectContext
{
public IObjectSet<SpecialClass<string>> SpecialClasses {
get { return CreateObjectSet<SpecialClass<string>>(); }
}
}
Now on the save I get an exception:
Mapping and metadata information could not be found for EntityType 'Prototype.SpecialClass`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.
On this line in the AModelContainer:
return CreateObjectSet<SpecialClass<string>>();
The default constructor of my generic 'SpecialClass' does nothing at the moment, should it?
public class SpecialClass<T>
{
public SpecialClass()
{ }
}
Or is this an issue with the ContextBuilder not knowing what to do exactly, is there a way to use builder.ComplexType(), or other method to guide it?
Or the CTP can't deal with this scenario yet...
That "`1" after my class name also doesn't sit well with me in the exception...