“参考文献”属性在客户端不可见
像往常一样,我对 ria 服务 + nhibernate 有疑问。问题是如何制作实体属性 ,使用“引用”映射,在客户端可见。问题是当你加载一个实体时 如果没有此字段并尝试保存它,则缺失值将在 db 内更新为 NULL。这是类架构:(
public class A
{
public virtual ComplexProperty property {get;set;}
}
public class AMap
{
public AMAP()
{
References(p=>p.property).Nullable().Column(“COMPLEX_PROPERTY_ID”);
}
}
我跳过了映射/声明关键属性的部分,因为它是在底层类中创建的) 通常包含和关联属性(如 HasMany)的技巧不起作用,因为里面没有真正的foreign_key属性 A级
So as usual I have an issue with ria service + nhibernate. The question is how to make an entity property
, mapped using “references”, visible on the client side. The problem is that when you load an entity
without this field and try to save it , then missing values are updated as NULL inside db. Here’s class schema:
public class A
{
public virtual ComplexProperty property {get;set;}
}
public class AMap
{
public AMAP()
{
References(p=>p.property).Nullable().Column(“COMPLEX_PROPERTY_ID”);
}
}
(I've skipped parts with mapping/declaring key property as it's made inside underlying classes)
Usual trick with include and association attribute(like with HasMany) does not work as there is no real foreign_key property inside
class A
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了一个适合我的解决方案。将“假”外键属性添加到未映射到数据库的 A 类就足够了。它允许定义关联:
最后要做的事情是从数据库检索对象后在客户端手动设置
ComplexPropertyId
(映射保持原样)。found a solution that's working for me. It's enough to add "fake" foreign key property to class A which is not mapped to database. It allows to define association:
Last thing to do is to set
ComplexPropertyId
manually on the client side after retrieving objects from db(mappings remain as they were).