LLBL Gen Predicate Filter
I am new to LLBLGen Pro and am checking for duplicate, I have the following SQL:
SQL:
select a.TopicId,atc.TopicCategoryId,a.Headline
from article a
inner join ArticleTopicCategory atc on atc.ArticleId = a.Id
where a.TopicId = 'C0064FAE-093B-466E-8745-230534867D2F'
and a.Headline = 'Test'
and atc.TopicCategoryId in ('004D64F7-474C-48F9-9887-17B1E7532A84')
Whenever I step though my function, it always returns 0:
LLBLGen Code:
public bool CheckDuplicateArticle(Guid topicId, List<Guid> categories, string headline)
{
ArticleCollection artic开发者_如何学编程les = new ArticleCollection();
PredicateExpression filter = new PredicateExpression();
RelationCollection relation = new RelationCollection();
relation.Add(ArticleEntity.Relations.ArticleTopicCategoryEntityUsingArticleId);
filter.AddWithAnd(ArticleFields.TopicId == topicId);
filter.AddWithAnd(ArticleTopicCategoryFields.Id == categories);
filter.AddWithAnd(ArticleFields.Headline == headline);
articles.GetMulti(filter, 0, null, relation);
return articles.Count > 0;
}
Any help would be appreciated!
Not enough info to be sure this is helpful, but:
I would start by verifying that the SQL generated is what you expect. Do this with SQL Profiler, or if you don't have access turn on tracing in LLBLGen: LLBL Help Link.
I don't think that syntax for a category filter will work. I think if you want to include multiple categories using the simple predicate syntax you are using (field == value), you need to pass an array of Guids, and not a generic list. I don't think generic lists work, and I'm surprised that it doesn't throw an exception. A quick thing to try would be "ArticleTopicCategoryFields.Id == categories.ToArray(). (Also, are they actual Guids, or strings made from Guids?)
Finally, if efficiency is at all an issue, you should look at using LLBL's GetScalar() functionality, so they you are just doing a simple, single-field query that returns a scalar value, and not projecting the full resultset onto an EntityCollection. Unfortunately I can't find a good link to this in the docs.
精彩评论