views:

33

answers:

1

I have the following LLBLGen code that retrieves articles by Category. Essentially it is selecting from the article table where the articles are not marked for deletion and joining on the ArticleTopicCategory table to retrieve specific categories (where category = 'string')

   ArticleCollection articles = new ArticleCollection();
                IPredicateExpression articlesFilter = new PredicateExpression();
                articlesFilter.Add(ArticleFields.IsFlaggedForDeletion != true);
                PrefetchPath prefetchTopic = new PrefetchPath(EntityType.ArticleEntity);
                prefetchTopic.Add(ArticleEntity.PrefetchPathTopic);
                prefetchTopic.Add(ArticleEntity.PrefetchPathArticleTopicCategories).SubPath.Add(ArticleTopicCategoryEntity.PrefetchPathTopicCategory);
                articles.GetMulti(articlesFilter, prefetchTopic);

I have added another table named SuppressedArticle which is a 1 to many and contains Id, OrganizationId, and ArticleId. The theory is that since articles are syndicated to multiple websites, if "Website A" did not want to publish "Article A" they could suppress it, i.e insert a record into the SuppressedArticle table.

On the article admin screen, i'd like to add a link button to suppress/unsuppress the article, by adding a left join with the two conditions like:

left join SuppressedArticle on (Article.Id = SuppressedArticle.articleId and SuppressedArticle.organizationId='CC177558-85CC-45CC-B4E6-805BDD1EECCC')

I tried adding the multiple join like so, but I cast/conversion error:

"Cannot implicitly convert type 'SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareValuePredicate' to 'SD.LLBLGen.Pro.ORMSupportClasses.IPredicateExpression'. An explicit conversion exists (are you missing a cast?)"

IRelationCollection relations = new RelationCollection();
                relations.Add(ArticleEntity.Relations.SuppressedArticleEntityUsingArticleId, JoinHint.Left).CustomFilter = new FieldCompareValuePredicate(SuppressedArticleFields.OrganizationId, ComparisonOperator.Equal, this.CurrentIdentity.OrganizationId);

Any help would be greatly appreciated!

+2  A: 

CustomFilter is of type IPredicateExpression, you create a predicate (of type IPredicate) and assign it to that property, which of course doesn't work :)

do:

IRelationCollection relations = new RelationCollection();
relations.Add(ArticleEntity.Relations.SuppressedArticleEntityUsingArticleId, JoinHint.Left)
             .CustomFilter = new PredicateExpression(SuppressedArticleFields.OrganizationId == this.CurrentIdentity.OrganizationId);
Frans Bouma
Thanks Otis! I added the prefetch path to the SuppressedArticle table with prefetchTopic.Add(ArticleEntity.PrefetchPathSuppressedArticle); but how do I deep bind in markup such as <asp:LinkButton ID="suppress" CommandArgument='<%# Eval("Id") %>' CommandName='<%# Eval("Articles.SuppressedArticle.ArticleId") == null ? "SuppressArticle" : "UnsuppressArticle" %>' Text='<%# Eval("Articles.SuppressedArticle.ArticleId") == null ? "Suppress" : "Unsuppress" %>' runat="server"></asp:LinkButton>
Neil
Not sure how you page looks like, but you could try our datasourcecontrol (prefetch paths also require some code in the code behind), or bind with code in the code behind?
Frans Bouma