views:

73

answers:

0

Hi.

I was messing around with CTP4 trying to get a feel of how mapping works and i've got this error that i can't figure out.

{"A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'OwnerID'."}

I read around that this was due to my pk being auto generated, but i do not specifically say that it should be auto generated.

These are my POCOs:

public class Person
{
 public int ID { get; set; }
 public string Name { get; set; }
 public virtual Item Item { get; set; }
}

public class Item
{
 public string Name { get; set; }
 public int OwnerID { get; set; }
}

And this is how i am mapping them:

public class ItemConfig : EntityConfiguration<Item>
{
 public ItemConfig()
 {
  HasKey(x => x.OwnerID); 
  //added the line below
  Property(x => x.OwnerID).StoreGeneratedPattern = StoreGeneratedPattern.None;
 }
}

public class PersonConfig : EntityConfiguration<Person>
{
 public PersonConfig()
 {
  HasKey(x => x.ID);

  HasOptional(x => x.Item)
   .WithRequired()
   .HasConstraint((i,p) => i.OwnerID == p.ID);
 }
}

It can't get more simple than this.

I followed what this guy said in his reply.

The error occurs when i add an Item.

Should this be creating my Person.ID as identity? Because it seems to be.

Also, i am creating the database with the CreateDatabase method.

Thanks

edit: It appears that EF Code First conventions say that a PK of type int will be mapped as and identity key.

Can this behavior be overriden?

edit2: Fixed, just set the storepattern to none. Edited the code to work.

related questions