English 中文(简体)
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 articles = 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:

  1. 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.

  2. 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?)

  3. 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.

问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签