473,382 Members | 1,733 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,382 software developers and data experts.

LINQ 2 SQL Group By Query... stuck on this.

I have the following tables that I have dragged into a .dbml file
(have only included the keys for simplicity).

CREATE TABLE [dbo].[Catalog](
[CatalogId] [int] NOT NULL)
CREATE TABLE [dbo].[CatalogFavorite](
[UserId] [uniqueidentifier] NOT NULL,
[CatalogId] [int] NOT NULL)

A user can add catalog items to their favorites. A user can also
browse other users favorites.

I am trying to write a LINQ to SQL query where I am seeing another
users favorites but I would also like to see if I have any of those
favorites in my own favorites. In SQL I would run this to get my
result:

SELECT Catalog.CatalogId, SUM(CASE WHEN
CatalogFavorite_1.UserId =
'my uniqueidentifier' THEN 1 ELSE 0 END) AS HasFavorite
FROM CatalogFavorite INNER JOIN
Catalog ON CatalogFavorite.CatalogId =
Catalog.CatalogId INNER JOIN
CatalogFavorite AS CatalogFavorite_1 ON
Catalog.CatalogId =
CatalogFavorite_1.CatalogId
WHERE (CatalogFavorite.UserId = 'uniqueidentifier of the
user I am
viewing')
GROUP BY Catalog.CatalogId

Can anyone help me doing this in LINQ? ANy help would be highly
appreciated.

Thanks in advance!
Aug 12 '08 #1
0 1277

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

Similar topics

28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
0
by: fiona | last post by:
Reading, Berkshire, UK 05 June 2007 - Crainiate Software make details available of the release of Objecto Framework 2.0, an upgrade to their enterprise business component framework, designed to...
4
by: shapper | last post by:
Hello, I have 2 tables: Aid, Aname ... Bid, Aid, Bname ... I need to get the records in B given a Bname and a Aname. I think I should use Inner Join. I wrote the following code:
7
by: =?Utf-8?B?VG9tIEJvbWJhZGls?= | last post by:
Question: Can an outer non-equijoin be simulated using LINQ? It's quite unfortunate that LINQ doesn't support literal joins based on anything other than equality. I know that this the most common...
8
by: Alcides | last post by:
Hello all, I learn about LINQ here in this forum. I been a VB.NET programmer for quite a while and we are using an internal solution for SQL access. I have some experience with C# and I started...
0
by: =?Utf-8?B?SHlwZXJjb2Rlcg==?= | last post by:
I'm encountering some strange behavior after deploying a ASP.net 3.5 website to production, i'm unable to reproduce these in my dev environment. This error seems to occur very randomly but it's...
14
by: thj | last post by:
Hi, I was wondering what you guys are using and why? LINQ to SQL or NHibernate? Thanks in advance, Tommy
2
by: shapper | last post by:
Hello, I have the following Linq query: List<PostsTaginsert = (from t in (from t in database.Tags join p in paper.Tags on t.Name equals p.Name select t).ToList() select new PostsTag {
5
by: giddy | last post by:
hi, If I have something like: class Person { //functions: static Person GetAllPersons(); static Person Search(string field,string value); }
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.