“参考文献”属性在客户端不可见

发布于 2024-09-24 06:58:44 字数 447 浏览 2 评论 0原文

像往常一样,我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅忆 2024-10-01 06:58:44

找到了一个适合我的解决方案。将“假”外键属性添加到未映射到数据库的 A 类就足够了。它允许定义关联:

       public class A
       {
           [Include]
           [Association("Relation1","ComplexPropertyId","Id")]
           public virtual ComplexProperty property {get;set;}
           public virtual int ? ComplexPropertyId {get;set;}
       }

最后要做的事情是从数据库检索对象后在客户端手动设置ComplexPropertyId(映射保持原样)。

public IQueryable<A> GetA()
{
 var item = repository.Query<A>();
 foreach(var a in item) a.ComplexPropertyId = a.ComplexProperty.Id;
 return item;
}

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:

       public class A
       {
           [Include]
           [Association("Relation1","ComplexPropertyId","Id")]
           public virtual ComplexProperty property {get;set;}
           public virtual int ? ComplexPropertyId {get;set;}
       }

Last thing to do is to set ComplexPropertyId manually on the client side after retrieving objects from db(mappings remain as they were).

public IQueryable<A> GetA()
{
 var item = repository.Query<A>();
 foreach(var a in item) a.ComplexPropertyId = a.ComplexProperty.Id;
 return item;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文