I want to create a nullable foreign key with type GUID
like this
[ForeignKey("CreatedBy")]
[Display(Name = "Created by")]
public Guid? CreatedById { get; set; }
public virtual User CreatedBy { get; set; }
But when I add migration and update the database it doesn't make it allow null in table design in SQL.
Is there another way to make it allow null through model first ?
int
but not withGuid
. I wonder if it's a bug in EF? Still not fixed in EF 6. :( – Apologeticsnullable Guid
on my model too and I wasn't noticing anynullable: true
on my brand new migration. Once applied, checked the relationships on the SMSS and saw it was allowing nulls. My problem was that I was trying to addGuid.Empty
instead of anull
– Gammonnull
instead ofGuid.Empty
? – Wadi