帮助删除重复项
我六个月前曾问过类似的问题,但仍未得到答复或提出任何建议。
问题就在这里。下面的代码返回重复的记录。 我正在使用的实际返回的记录集是 Model.Product。 该查询正在查看 ProductSkus 表中的 DateAdded 字段,以查看产品是否应显示。 唯一的问题是,如果超过 1 个 ProductSkus 符合特定产品的要求,我会得到重复的记录。我不能要这个。 我只关心访问 Model.Product 中包含的数据。不是型号.产品.ProductSkus。
有人遇到过类似的情况吗? 关于如何获得我正在寻找的结果有什么想法吗?
提前致谢。
ICriteria query = this.Session.CreateCriteria<Model.Product>();
query.CreateAlias("ProductSkus", "ProdSku", JoinType.InnerJoin)
.AddOrder(new Order("ProdSku.DateAdded", false))
.AddOrder(new Order("Name", true))
.Add(Restrictions.Ge("ProdSku.DateAdded", myDate))
.SetMaxResults(100);
结果=查询.List();
I have asked a similar question 6 months ago that still has not been answer or any suggestions made.
Here is the problem. The code below is returning duplicate records.
The actual returned record set I am working with is the Model.Product.
The query is looking at the DateAdded field within ProductSkus table to see if the Product should show.
The only problem is if more then 1 ProductSkus match the requirement for a particular Product I get duplicate records. I can't have this.
I only care about accessing the data contained in Model.Product. Not Model.Product.ProductSkus.
Has anyone ran into a similar situation?
Any ideas on how to get the results I am looking for?
Thanks in advance.
ICriteria query = this.Session.CreateCriteria<Model.Product>();
query.CreateAlias("ProductSkus", "ProdSku", JoinType.InnerJoin)
.AddOrder(new Order("ProdSku.DateAdded", false))
.AddOrder(new Order("Name", true))
.Add(Restrictions.Ge("ProdSku.DateAdded", myDate))
.SetMaxResults(100);
result = query.List();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该确保您的查询/条件使用“resultransformer”。在这种情况下,您将需要 DistinctRootEntityResultTransformer。
接下来,该关联是如何映射的?它是作为一个包映射的,还是作为一个集合映射的?
You should make sure that your query/criteria uses a 'resultransformer'. In this case, you'll need the DistinctRootEntityResultTransformer.
Next to that, how is that association mapped ? Is it mapped as a bag, or as a set ?