问题描述
我与Durandal&使用asp.net mvc一起工作微风模板。
I work with asp.net mvc with Durandal & breeze templates.
我有以下代码优先类:
第一种情况:
public class Transport
{
[Key]
public int Id { get; set; }
...
public int? SenderId { get; set; }
public virtual SendRecv Sender { get; set; }
}
public class SendRecv
{
[Key]
public int Id { get; set; }
...
public virtual List<Transport> Transports { get; set; }
}
然后,我可以轻松地从类型为 SendRecv
:
Then I can easily get all my related transports from my observable of type SendRecv
:
if (sendRecvs()[i].transports().length > 0)
{
...
}
问题:我在运输
SendRecv 的新引用>像这样的实体:
The problem: I add a new reference to the same entity SendRecv
in my Transport
entity like this:
第二种情况:
public class Transport
{
[Key]
public int Id { get; set; }
...
public int? SenderId { get; set; }
public int? ReceiverId { get; set; }
public virtual SendRecv Sender { get; set; }
public virtual SendRecv Receiver { get; set; }
}
然后,我再也无法获得相关的运输了!我的 SendRecv
实体中名为 transport
的导航属性不再存在。
Then I cannot get my related transports anymore! The navigation property named transport
from my SendRecv
entity does not exists anymore.
这将不再起作用:
if (sendRecvs()[i].transports().length > 0)
{
...
}
PS:我很确定这在将微风迁移到1.4.2之前是可行的。
PS: I'm pretty sure this worked before the migration of breeze to 1.4.2
任何想法吗?
谢谢。
推荐答案
我假设您只希望在SendRecv中收集一个Transport。
如果是这样,请尝试以下操作(使用流畅的API):
I'm assuming you only want one collection of Transport in SendRecv.If so, try this (using fluent API):
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
modelBuilder.Entity<SendRecv>()
.HasMany(c => c.Transports)
.WithRequired(c => c.Sender)
.WillCascadeOnDelete(false);
modelBuilder.Entity<SendRecv>()
.HasMany(c => c.Transports)
.WithRequired(c => c.Receiver)
.WillCascadeOnDelete(false);
}
现在,如果您想要2个运输清单(即Transports1和Transports2),请尝试:
Now, if you want 2 Transport lists (i.e. Transports1 and Transports2) then try:
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
modelBuilder.Entity<SendRecv>()
.HasMany(c => c.Transports1)
.WithRequired(c => c.Sender)
.WillCascadeOnDelete(false);
modelBuilder.Entity<SendRecv>()
.HasMany(c => c.Transports2)
.WithRequired(c => c.Receiver)
.WillCascadeOnDelete(false);
}
这篇关于微风1.4.2迁移后导航属性不再起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!