如何在一个公共类中对多个 DataServices 的多个实体进行过滤?
层数据库和每个表都有一个 DataSetId,我绝对希望确保数据始终正确分区。
目前我正在使用 QueryInterceptor 属性,但它很混乱且过度重复并且容易出错。一些新的开发人员可能会添加新表并忘记按 DataSetId 进行过滤,或者只是重命名表。因此,我将其放入基类中,但我的存储库的 IQuerable 属性从未被调用。
我有一个继承自 ObjectContext 的“CoreRepository”类,并且我的每个 IQueryable 集合都使用“CoreObjectSet”。 CoreObjectSet 通过始终添加表达式来按 DataSetId 进行过滤来扩展 ObjectSet。直接使用时效果很好。但是,当用于 DataService 时,DataService 永远不会调用存储库上集合的 Get 访问器。它似乎是作弊,根本不使用它们并直接访问数据。
有没有办法让DataService通过存储库类正确访问(并且仍然获得作为SQL传递查询的效率)?
如果这是这种行为,如果它甚至不打算使用该类,为什么还要使 T 的 DataService 呢?对于 ADO 团队来说,忽略它并直接使用 edmx 似乎是一种 hack。
谢谢 亚伦
Tier database and every single table has a DataSetId and I absolutely want to be sure that the data is always partitioned correctly.
Currently I'm using the QueryInterceptor attribute but it's messy and overly repetitive and prone to errors. Some new Dev could add a new table and forget to filter by DataSetId, or just rename a table. So I've put this in a base class but the IQuerable properties of my repository are never called.
I have a "CoreRepository" class that inherits from ObjectContext, and each of my IQueryable collections uses "CoreObjectSet". CoreObjectSet extends ObjectSet by always adding an expression to filter by DataSetId. When used directly this works fine. But when used for a DataService the Get accessor for the collections on the Repository are never called by the DataService. It appears to be cheating and not using them at all and accessing the data directly.
Is there a way to get the DataService to access through the repository class correctly (And still get the efficiency of passing through the query as SQL)?
If this is the behaviour why even make DataService of T anyway if it's not even going to use the class? For the ADO team to just ignore it and use the edmx directly seems like a hack.
Thanks
Aaron
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来唯一的解决方法是使用 T4 模板来生成 DataService。我更喜欢基类或某种可重用处理程序,但 ADO 在这里让我别无选择。
Looks like the only way around it is to use a T4 template to generate the DataService. I much prefer a base class or some kind of reusable handler but ADO has given me no choice here.