473,324 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Re: Linq. OrderBy and Where.

Ah right - I just saw your explanation of "Source"; yes - I'd have 2
queries, then:

switch(Source) {
case "File":
viewData.blah = (from t in database.Tags
where t.FileCount != 0
orderby t.FileCount
select new {...}).ToList();
break;
case "Post":
viewData.blah = second query;
break;
}

Marc

Sep 3 '08 #1
4 3549
On Sep 3, 9:40*pm, Marc Gravell <marc.grav...@gmail.comwrote:
Ah right - I just saw your explanation of "Source"; yes - I'd have 2
queries, then:

switch(Source) {
* case "File":
* * viewData.blah = (from t in database.Tags
* * * * * * * where t.FileCount != 0
* * * * * * * orderby t.FileCount
* * * * * * * select new {...}).ToList();
* * break;
* case "Post":
* * viewData.blah = second query;
* * break;

}

Marc
Thanks!
Sep 3 '08 #2
On Sep 3, 9:40*pm, Marc Gravell <marc.grav...@gmail.comwrote:
Ah right - I just saw your explanation of "Source"; yes - I'd have 2
queries, then:

switch(Source) {
* case "File":
* * viewData.blah = (from t in database.Tags
* * * * * * * where t.FileCount != 0
* * * * * * * orderby t.FileCount
* * * * * * * select new {...}).ToList();
* * break;
* case "Post":
* * viewData.blah = second query;
* * break;

}

Marc
Not done yet ...

viewData.TagsPapers = (from t in database.Tags
where t.FileCount != 0
orderby t.FileCount
select new TagPaper {
Tag = t,
FileCount = t.FilesTags.Count,
PostCount = t.PostsTags.Count
}).ToList();

I get an error on where and orderby ...

FileCount is not a property of Tag! It is a property of TagPaper ...
this is why I don't know how to do this.

Any idea?

Thanks,
Miguel
Sep 3 '08 #3
either: where t.FilesTags.Count != 0
or:
select new TagPaper {
Tag = t,
FileCount = t.FilesTags.Count,
PostCount = t.PostsTags.Count
} into tmp
where tmp.FileCount != 0
select tmp).ToList();
Sep 3 '08 #4
On Sep 3, 10:15*pm, Marc Gravell <marc.grav...@gmail.comwrote:
either: where t.FilesTags.Count != 0
or:
select new TagPaper {
* Tag = t,
* FileCount = t.FilesTags.Count,
* PostCount = t.PostsTags.Count} into tmp

where tmp.FileCount != 0
select tmp).ToList();
I have the following:

viewData.TagsPapers = (from t in database.Tags
orderby t.Name
select new TagPaper {
Tag = t,
PostCount = t.PostsTags.Count
} into tp
where tp.PostCount != 0
orderby tp.PostCount
select tp).Take(50).ToList();

I need the items to be ordered by name but before that I want to get
the 50 items with the highest PostCount.
So I ordered it by PostCount and used Take(50).

However, I think Take is getting the first 50 items of the final list
and not from the tp which is ordered by PostCount.

Does this makes any sense? How can I fix this?

Note: I am using take because I think there is no TOP in Linq.

Thanks,
Miguel

Sep 3 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mucahit ikiz | last post by:
I cant make a full dynamic query in LINQ I have 2 situation methods (only_exp_query, only_tbl_query) those are working. .... using System.Linq.Dynamic; using System.Data.Linq; .... string...
2
by: shapper | last post by:
Hello, I have the following LINQ: List<Tagtags = (from t in database.Tags select t).ToList(); I need to restrict my results and for that I have two parameters: StartWidth and N
0
by: Marc Gravell | last post by:
It isn't clear what Source is here - is this a property of a Tag? If there are both File and Post records in the set, how do you sort it? You can union LINQ queries, so you might have var qry1...
13
by: Dan Tallent | last post by:
I have a query which I would like to convert to LINQ. I am having problems finding good examples or references that cover more complex queries. Here is the SQL command I would like to rewrite...
21
by: hrishy | last post by:
Hi Will LINQ be ported to Python ? regards Hrishy
1
by: shapper | last post by:
Hello, I am using the following: PostPaper paper = (from p in database.Posts where p.PostID == id select new PostPaper { Post = p, Tags = (from pt in database.PostsTags join t in...
7
by: raylopez99 | last post by:
Thanks Dan Tallent, that worked. But I defy anybody who thinks this Lambda expression is more logical than the Linq/Sql equivalent. For example, both the below fragments yield the same thing (a...
0
by: dlouche | last post by:
I have a method that contains the linq query: var query = from c in db.Categories join pc in db.ProductsToCategories on c.ID equals pc.CategoryID where...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.