I'm using Entity Framework CTP5 (code-first) and I have two classes:
public class Order
{
public int Id {get;set;}
public decimal SomeOtherProperty1 {get;set;}
//navigation property
public virtual ICollection<OrderLine> OrderLines { get; set; }
}
and
public class OrderLine
{
public int Id {get;set;}
public int OrderId {get;set;}
public decimal SomeOtherProperty2 {get;set;}
//navigation property
public virtual Order Order { get; set; }
}
And I have the following configuration class for OrderLine class:
public partial class OrderLineMap : EntityTypeConfiguration<OrderLine>
{
public OrderLineMap()
{
this.HasKey(ol=> ol.Id);
this.HasRequired(ol=> ol.Order)
.WithMany(o => o.OrderLines)
.HasForeignKey(ol=> ol.OrderId);
}
}
Currently if you create an 'OrderLine' instance, you have to specify an 'Order' instance.
The question: how can I make ol.Order property optional (null in some cases)? Is it possible?