Question

I'm running MVC3 with EntityFramework CTP5, SQL Server 2008

I don't believe this is the issue but figure I might mention it. Because I'm lazy I created Linq to SQL and copied the property definitions and pasted into my own Model, then deleted the dbml file.

Is it possible that some of the data types might be wrong for the EntityFramework? I'm still fairly new to EntityFramework.

I added the [key] annotation.

[Key]
public System.Guid FormID;

I still get this error.

System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation: 
System.Data.Edm.EdmEntityType: : EntityType 'FormInfo' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: The EntitySet FormInfoes is based on type FormInfo that has no keys defined.

I noticed that "FormInfo" is set in the EntitySet to "FormInfoes". So, I added this to my context

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    base.OnModelCreating(modelBuilder);
}

I initializing the context.

DbDatabase.SetInitializer<SQLServerContext>(null);

Since the DB is already there, I don't want to recreate or drop it.

Thanks for anyone's help!

Was it helpful?

Solution

You have defined a field. Not a property. Change the declaration to a property

[Key]
public System.Guid FormID { get; set; }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top