473,406 Members | 2,390 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,406 software developers and data experts.

LINQ to SQL query question

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.

The following query would return all favorites for a particular user.

SELECT *
FROM CatalogFavorite
WHERE UserId = uniqueidentifier of the user I am viewing'

How can I rewrite the query to see if any of that users favorites are
in my favorites (I have my uniqueidentifer available for this query).
I assume I need another column (maybe of type bit) where the query
would return a true if I have the item in my favorites as well or a
false if I don't.

Any help would be highly appreciated.

Thanks
Aug 11 '08 #1
1 1157
I might want to add that in SQL I would do something like:

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

Not sure how this would be done in LINQ.

Thanks
Aug 11 '08 #2

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...
4
by: BeSharp | last post by:
I recently stumbled across a pretty interesting LINQ to SQL question and wonder, whether anybody might have an answer. (I'm doing quite some increasing LINQ evangelism down here in Germany.). ...
1
by: 0to60 | last post by:
Let's say we have your basic Invoices and InvoiceItems table. If we load this in with LINQ: var query = from i in db.Invoices select i; When I then loop through my invoices, if I wanna...
2
by: AAAAA | last post by:
Hi guys I have a one question, is Linq to Sql good in pefornace? is better that traditional method? ismore than speed?? or is same? Thanks.. Regards Cesar
6
by: Plissskin | last post by:
I need to create an "ad-hoc" filtering page in a web app we are building. The page would display a number of drop down lists, text boxes, and radio lists and allow the user to select (enter) some...
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
20
by: raylopez99 | last post by:
Inspired by Chapter 8 of Albahari's excellent C#3.0 in a Nutshell (this book is amazing, you must get it if you have to buy but one C# book) as well as Appendix A of Jon Skeet's book, I am going...
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 {
2
by: giddy | last post by:
hi, Yes its a design question again. =) If I have something like: class Person { //functions: static Person GetAllPersons(); static Person Search(string field,string value);
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.