473,809 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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] [uniqueidentifie r] 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.Catalog Id, SUM(CASE WHEN
CatalogFavorite _1.UserId =
'my uniqueidentifie r' THEN 1 ELSE 0 END) AS HasFavorite
FROM CatalogFavorite INNER JOIN
Catalog ON CatalogFavorite .CatalogId =
Catalog.Catalog Id INNER JOIN
CatalogFavorite AS CatalogFavorite _1 ON
Catalog.Catalog Id =
CatalogFavorite _1.CatalogId
WHERE (CatalogFavorit e.UserId = 'uniqueidentifi er of the
user I am
viewing')
GROUP BY Catalog.Catalog Id

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

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

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

Similar topics

28
16436
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 write a safe but easy implementation (i.e. no codedom) for an IBindingListView.Filter (by compiling to a Predicate<T>). Anybody know if this is possible at all? Marc
0
1783
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 make it easy for programmers to create agile persisted business objects that are reusable, customisable and scalable, without additional developer tools. Objecto uses object persistence and managed database technology to allow developers to...
4
6789
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
4192
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 scenario, and although the efficiency of other types of joins is often debatable, they are often darned useful. In T-SQL I have dozens of such useful queries with joins based on such operations as prefix or suffix comparisons (using the LIKE...
8
2115
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 to write a blog to share my experiences with a sql framework. I would like to hear some opinions about LINQ, is it the main thing when accessing sql now? what are the main advantages/disavantages using it. Nothing fancy, just drop a few lines...
0
2367
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 occuring enough to be a real cause for concern. The errors occur a couple times a week and the website is hit with constant traffic 24x7. Below are the two errors that are encountered. I had read something about MARS causing errors like this but...
14
3692
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
2402
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
1083
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
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10635
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10378
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9198
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.