Reputation: 2357
I have the below database tables:
FundAllocation {below two columns make a composite primary key}
[CurrencyRefId] (int) {FK to a table Currency.CurrencyId}
[AllocationRefId] (int) {FK to Allocation.AllocationId}
Allocation
[AllocationId] (int) {PK Identity Column}
[AllocationTitle] (varchar)
Below are my entities corresponding to the above table:
public class FundAllocation
{
[Key]
[Column(Order = 1)]
public int CurrencyRefId { get; set; }
[Key]
[Column(Order = 2)]
public int AllocationRefId { get; set; }
[ForeignKey("AllocationRefId")]
public Allocation Allocation { get; set; }
}
public class Allocation
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int AllocationId { get; set; }
public string AllocationTitle { get; set; }
}
Now when I get the FundAllocation list from the data context, its Allocation property is set to null. What additional configuration is needed to achieve this Zero-to-One relationship ?
Upvotes: 0
Views: 47
Reputation: 7800
To solve your problem you must populate the property by:
public virtual Allocation Allocation { get; set; }
Upvotes: 1