Condition

S

shapper

Hello,

I have the following code:

postBook.Leafs = (from p in database.Posts
let tags = p.PostsTags.Select(pt =>
pt.Tag).DefaultIfEmpty()
orderby p.UpdatedAt descending
where p.PostsTags.Where(pt => pt.Tag.Name ==
tag || tag == null).Count() != 0 && p.IsPublished == true
select new PostLeaf {
Post = p,
Tags = tags.ToList(),
TagsCSV = string.Join(", ", tags.Select(t =>
t.Name).ToArray())
}).ToPagedList(page.HasValue ? page.Value -
1 : 0, LogPageSize);

This code should get:

1. All published posts if tag is not provided;
2. All published posts associated to a tag if provided.

I am getting a problem. When tag is not provided (Case 1) I get all
published posts but the posts that are not associated to any tag are
not included.

How can I solve this problem?

Thanks,
Miguel
 
S

shapper

Hello,

I have the following code:

      postBook.Leafs = (from p in database.Posts
                        let tags = p.PostsTags.Select(pt =>
pt.Tag).DefaultIfEmpty()
                        orderby p.UpdatedAt descending
                        where p.PostsTags.Where(pt => pt.Tag.Name ==
tag || tag == null).Count() != 0 && p.IsPublished == true
                        select new PostLeaf {
                          Post = p,
                          Tags = tags.ToList(),
                          TagsCSV = string.Join(", ", tags.Select(t =>
t.Name).ToArray())
                        }).ToPagedList(page.HasValue ? page.Value -
1 : 0, LogPageSize);

This code should get:

1. All published posts if tag is not provided;
2. All published posts associated to a tag if provided.

I am getting a problem. When tag is not provided (Case 1) I get all
published posts but the posts that are not associated to any tag are
not included.

How can I solve this problem?

Thanks,
Miguel

Please, anyone?

Thank You,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Filter 1
Linq. Please, need help. 1
Linq. Aggregate 4

Top