【发布时间】:2010-10-05 00:16:10
【问题描述】:
我正在开发一个 silverlight 应用程序,我正在使用 RIA 数据服务和 nHibernate。
目前,我有一个与另一个实体存在一对多关系的实体。
public class Employer {
[Key]
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
public class Person {
[Key]
public virtual int Id { get; set; }
public virtual string Name { get; set; }
[Include]
[Association("PersonCurrentEmployer", "CurrentEmployerId", "Id", IsForeignKey = true)]
public virtual Employer CurrentEmployer { get; set; }
public virtual int? CurrentEmployerId { get; set; }
}
属性CurrentEmployerId 设置为在映射中不插入和不更新。
在 Silverlight 端,我将人的 CurrentEmployer 属性设置为客户端的现有雇主提交更改。
personEntity.CurrentEmployer = megaEmployer;
dataContext.SubmitChanges();
在服务器端,个人实体的CurrentEmployerId 设置为megaEmployer.Id,但CurrentEmployer 是null。因为我使用CurrentEmployer 属性而不是CurrentEmployerId 来保存关系,所以关系没有改变。
有没有办法强制 RIA 发送带有保存的 CurrentEmployer 对象,还是我必须在服务器端使用 CurrentEmployerId 来加载雇主并将其设置为 CurrentEmployer?
【问题讨论】:
-
是的,我也有同样的问题:stackoverflow.com/questions/4921465/… 我想NHibernate似乎仍然没有足够的支持;我们应该操作 ForeighKey,而不是实体! scip.be/index.php?Page=ArticlesNET30&Lang=NL 真可惜,我认为微软团队应该听我们的=)
标签: silverlight nhibernate ria