Linq. Select

S

shapper

Hello,

I have the following method to get all tags in a table:

// GetTags
public IQueryable<Tag> GetTags(IList<String> names) {
IQueryable<Tag> tags = (from t in
context.aspnet_Tags
orderby t.Name descending
select new Tag {
Id = t.TagId,
Name = t.Name
}).AsQueryable();
return tags;
} // GetTags

How can I get only the tags which name is contained in names input?
I would like to not care about the case ...

Thanks,
Miguel
 
S

shapper

[...]
How can I get only the tags which name is contained in names input?
I would like to not care about the case ...

See "where".

I was thinking the wrong way ... I was thinking on some kind of join.

But I think the follows solves it well:

IQueryable<Tag> tags = (from t in context.aspnet_Tags
where names.Contains(t.Name)
orderby t.Name descending
select new Tag {
Id = t.TagId,
Name = t.Name
}).AsQueryable();
return tags;

Thanks,
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


Top