I get a ModelValidationException (below) when working with "EF-Code First". He wants me to define the Key, but I'm not sure what exactly this means ...
public class Unit
{
Guid id;
String public_id;
String name;
bool deleted;
}
public class MyDataContext : DbContext
{
public DbSet<Unit> Units { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Unit>().ToTable("sometable");
}
}
[TestFixture]
public class DataTests
{
[Test]
public void Test()
{
MyDataContext database = new MyDataContext();
var o = database.Units;
Console.WriteLine(o.Count());
Assert.IsTrue(true);
}
}
System.Data.Entity.ModelConfiguration.ModelValidationException: one or more validation errors were detected during model generation:
System.Data.Edm.EdmEntityType :: EntityType 'Unit' does not have a key. Define a key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet units are based on the Unit type, which does not have specific keys.
source
share