我有很多实体。其中一个OrderLine
实体使用了一些关系。这与AccountTransaction
有关。当我从上下文中获得AccountTransaction
类时,我可以使用延迟加载获得OrderLine
个记录。但是当我从上下文OrderLine
获得AccountTransaction
类时,navigation属性为null。
我怎么解决这个问题?
public partial class OrderLine : Base
{
[Key, ForeignKey("AccountTransaction")]
public int OrderLineId { get; set; }
public virtual AccountTransaction AccountTransaction { get; set; }
}
public class AccountTransaction
{
[Key]
public int TransactionId { get; set; }
[ForeignKey("OrderLine")]
public int? OrderLineId { get; set; }
public virtual OrderLine OrderLine { get; set; }
}
var orderLine = context.OrderLines.Find(167069);
var accTransaction = context.AccountTransactions.Find(38770);
//orderLine.AccountTransaction; //here account transaction is null
//accTransaction.OrderLine;//here orderLine is not null.
答案 0 :(得分:0)
您误导Function betterSearch(searchValue1 As Variant, searchValue2 As Variant, _
searchColumn1 As Range, searchColumn2 As Range, _
resultColumn As Range)
Dim i As Long
For i = 1 To Cells(Rows.Count, searchColumn1.Column).End(xlUp).Row
If Cells(i, searchColumn1.Column).Value = searchValue1 _
And Cells(i, searchColumn2.Column).Value = searchValue2 Then
betterSearch = Cells(i, resultColumn.Column)
MsgBox ("found")
Exit For
End If
betterSearch = "Not found"
Next
End Function
。它用于指定子记录中关系的关键字段,在本例中为[ForeignKey]
。尝试将模型更改为以下内容:
AccountTransaction
让我知道它是否有效或是否遇到其他问题。 :)