如何传播的一个参数为一个ORM加入 [英] How to propagate a parameter for joins in a ORM

查看:93
本文介绍了如何传播的一个参数为一个ORM加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个问题,我之前问的续集。到目前为止,对模式演化问题的策略,我想实现正在慢慢改变尺寸。我现在有这个问题看起来如下。请看下面的数据模型:

This is a sequel of a question I asked before. So far the strategy for Schema Evolution problem I'm trying to implement is Slowly changing dimension. The problem that I have now looks as following. Consider the following data model:

class Bar
{
    int id;
    int param;

    double x;
    double y;
}

class Foo
{
    int id;
    int param;

    string name;
    string description;

    collection<Bar> bars;
}

class Delta
{
    int id;
    int param;

    double rating;
}

class RootEntity
{
    int id;
    int param;

    collection<Foo> foos;
    collection<Delta> deltas;
}

请注意,所有的实体都 INT参数属性。它具有相同的名称,但它不是外键。
这是一个相当简化的模型,只是作为一个例子。考虑到馆藏的庞大并对象树的方式更加复杂。在的EntityFramework技术
我可以这样做:

Note, that all entities have int param attribute. It has the same name but it is not foreign key. This is quite simplified model, just as an example. Consider that collections are huge and object tree is way more sophisticated. In EntityFramework technology I can do something like:

  class MyDbContext : DbContext
  {
        public DbSet<RootEntity> rootEntities { get; set; }
  }



我想要做的是限制,通过选择参数。这可以是如下

dbContext.rootEntities.Where(e => e.param == some_value);



的问题是,只有dbContext.rootEntities将在生成的SQL代码进行过滤。其余的(与富,酒吧和Delta联接)不会被过滤。
因此是一个问题:如何传播。凡(E => e.param == SOME_VALUE)来所有联接为基础对象选择

The problem is that only dbContext.rootEntities will be filtered in generated SQL code. The rest (joins with Foo, Bar and Delta) will not be filtered. Hence is the question: how to propagate .Where(e => e.param == some_value) to all joins for underlying objects selection?

我在看的的EntityFramework或NHibernate的解决方案。

I'm looking at solutions for EntityFramework or NHibernate.

感谢。

推荐答案

与NHibernate可以使用过滤器每个这样的表:

With NHibernate you can use Filter per table like this:

public class FooMap : ClassMap<Foo>
{
    ApplyFilter("Param", "param = :paramValue");
}

public class BarMap : ClassMap<Bar>
{
    ApplyFilter("Param", "param = :paramValue");
}

public class XyzMap : ClassMap<Xyz>
{
    // This can be the (abstract?) base class map
    ApplyFilter("Param", "param = :paramValue");
}

在你调用由出席会议的所有实体启用过滤器:

Before you call any entity by the session enable the filter:

Session.EnableFilter("Param").SetParameter("paramValue", objValue);

这篇关于如何传播的一个参数为一个ORM加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆