I want to create one to one relationship in EF with MVC but getting little bit confused
here are my model...
public class Event
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public Guid CategoryId { get; set; }
public string EventTitle { get; set; }
public string ImgUrl { get; set; }
public string Venue { get; set; }
public int SeatsAvailable { get; set; }
public string Description { get; set; }
public DateTime EventDate { get; set; }
public DateTime EventAddedDate { get; set; }
[Required]
[ForeignKey("CategoryId")]
public virtual Category Category { get; set; }
}
And
public class Category
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public string CategoryName { get; set; }
public virtual Event Event { get; set; }
}
I want to store the Category Id in Event so I created relation in fluentApi like this...
modelBuilder.Entity<Event>()
.HasRequired(a => a.Category)
.WithOptional(b => b.Event);
but getting this error when updating database...
System.Data.Entity.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role 'Event_Category_Source' in relationship 'Event_Category'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.