473,406 Members | 2,549 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 > Group

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 {
PostID = paper.Post.PostID,
TagID = t.TagID
}).ToList();

How can I convert this query to use Linq's Group instead of using the
sub query?

Tags table has 2 fields: TagID and Name
PostTags table has 2 fields PostId and TagID

Thanks,
Miguel

Sep 29 '08 #1
2 2374
shapper wrote:
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 {
PostID = paper.Post.PostID,
TagID = t.TagID
}).ToList();

How can I convert this query to use Linq's Group instead of using the
sub query?

Tags table has 2 fields: TagID and Name
PostTags table has 2 fields PostId and TagID
Miguel, you ask about 4, 5 linq questions a day. Now, I'm not sure if
you're a professional developer or just a guy with a hobby project, but
either way, isn't it more productive for you to simply get a good book
about the subject, work your way through it and then apply that
knowledge to your work with linq? E.g. get "Linq in Action" from
amazon.com and use the knowledge in there to answer your own questions.
We can step in every day and help you with the question(s) you have that
day, but I get the feeling you keep running into the same problems over
and over with slightly different parameters, i.o.w.: you understood the
trick to solve yesterday's problem, but didn't completely
understand/grasp the knowledge/idea behind the solution of yesterday's
questions to answer today's questions.

FB
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Sep 29 '08 #2
On Sep 29, 10:28*am, "Frans Bouma [C# MVP]"
<perseus.usenetNOS...@xs4all.nlwrote:
shapper wrote:
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 {
* * * * * * * * * * * * * * * * *PostID = paper.Post.PostID,
* * * * * * * * * * * * * * * * *TagID = t.TagID
* * * * * * * * * * * * * * * *}).ToList();
How can I convert this query to use Linq's Group instead of using the
sub query?
Tags table has 2 fields: TagID and Name
PostTags table has 2 fields PostId and TagID

* * * * Miguel, you ask about 4, 5 linq questions a day. Now, I'mnot sure if
you're a professional developer or just a guy with a hobby project, but
either way, isn't it more productive for you to simply get a good book
about the subject, work your way through it and then apply that
knowledge to your work with linq? E.g. get "Linq in Action" from
amazon.com and use the knowledge in there to answer your own questions.
We can step in every day and help you with the question(s) you have that
day, but I get the feeling you keep running into the same problems over
and over with slightly different parameters, i.o.w.: you understood the
trick to solve yesterday's problem, but didn't completely
understand/grasp the knowledge/idea behind the solution of yesterday's
questions to answer today's questions.

* * * * * * * * FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website:http://www.llblgen.com
My .NET blog:http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Hi Frank,

4 to 5 posts a day is an exaggeration ... maybe on a specific day ...

What I am doing is converting all SQL code I have to LINQ and this is
lately I have been posting a few post on LINQ.

For reference, I am a free lancer, and I am using MSDN Linq 101
Examples ...

In this post, as in many others, I am more looking for a confirmation
if what I am doing is the best way to do it:

I have 2 tables:

Both Tags and paper.Tags are List<Tag>.
Tag is a class with two properties: TagID and Name.

In Tags both TagID and Name are defined.
In paper.Tags only Name is defined.

So I need to get the TagID's from Tags on the Names I have in
paper.Tags and create the PostsTags.

This is working:
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 {
PostID = paper.Post.PostID,
TagID = t.TagID
}).ToList();

But to be honest it seems the same as:

List<PostsTagtags = (from t in database.Tags
join pt in paper.Tags on t.Name equals
pt.Name
select new PostsTag {
PostID = paper.Post.PostID,
TagID = t.TagID
}).ToList();

I don't think I need the subquery or groupby because I am making a one
to one relation between Tags and paper.Tags.

This is what I am trying to check.

Thank You,
Miguel
paper.Tags >
Sep 29 '08 #3

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

Similar topics

3
by: David Veeneman | last post by:
I've been hearing a lot about LINQ in connection with Orcas, the next release of VS.NET. Micorosoft touts LINQ as the Next Big Breakthrough, but it looks to me like further muddying of application...
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:
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...
1
by: Amil Hanish | last post by:
I had a VS 2005 web app (not using Linq yet). I migrated to VS 2008 and the app still worked fine. Now I want to try out Linq. I modified the web.config to load the Linq DLLs and added "using...
0
by: Marc Gravell | last post by:
Well, I'd have to wonder why you don't just use Dictionary<,/ SortedList<,/ SortedDictionary<,(and just use .Keys and .Values) But something like below: List<KeyValuePair<DateTime, double>list...
9
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
Hi all: after reading different places/sites about linq... I ran into these questions: 1. What framework do we need to run linq ? (does it depend on what version of visual studio we have?) how...
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
21
by: hrishy | last post by:
Hi Will LINQ be ported to Python ? regards Hrishy
3
by: bob laughland | last post by:
Hi All, I am using a combination of LINQ to SQL and bulk insert. In the process of performing 'one unit of work' I will be doing things like reading, and deleting records using LINQ to SQL and...
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
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
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
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.