473,397 Members | 1,950 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,397 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 3551
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.