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

Linq. String

Hello,

I have the following LINQ query:

PostPaper paper = (from p in database.Posts
where p.PostID == id
select new PostPaper {
Post = p,
Tags = new List<Tag>(
from pt in database.PostTags
join t in database.Tags on pt.TagID
equals t.TagID
where pt.PostID == p.PostID
select t).ToString()
}).SingleOrDefault();

Tags should be a string with CSV values. So I added it the ToString()
at the end. However it is returning a List.

What am I doing wrong?

Thanks,
Miguel
Aug 21 '08 #1
5 1941
shapper wrote:
Tags = new List<Tag>(
from pt in database.PostTags
join t in database.Tags on pt.TagID
equals t.TagID
where pt.PostID == p.PostID
select t).ToString()
}).SingleOrDefault();

Tags should be a string with CSV values. So I added it the ToString()
at the end. However it is returning a List.

What am I doing wrong?
If you want a string with comma separated values then you could try
Tags = (from pt in database.PostTags
join t in database.Tags on pt.TagID
equals t.TagID
where pt.PostID == p.PostID
select t).Aggregrate((a, b) =a + "," + b)

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 21 '08 #2
On Aug 21, 4:11*pm, Martin Honnen <mahotr...@yahoo.dewrote:
shapper wrote:
* * * * * * * * * * * * * *Tags = new List<Tag>(
* * * * * * * * * * * * * * *from pt in database.PostTags
* * * * * * * * * * * * * * *join t in database.Tags on pt.TagID
equals t.TagID
* * * * * * * * * * * * * * *where pt.PostID == p.PostID
* * * * * * * * * * * * * * *select t).ToString()
* * * * * * * * * * * * *}).SingleOrDefault();
Tags should be a string with CSV values. So I added it the ToString()
at the end. However it is returning a List.
What am I doing wrong?

If you want a string with comma separated values then you could try
* *Tags = * * * * * * * * * * * * * * *(from pt in database.PostTags
* * * * * * * * * * * * * * * join t in database.Tags on pt.TagID
equals t.TagID
* * * * * * * * * * * * * * * where pt.PostID == p.PostID
* * * * * * * * * * * * * * * select t).Aggregrate((a, b) =a + "," + b)

--

* * * * Martin Honnen --- MVP XML
* * * *http://JavaScript.FAQTs.com/
I get an error on the Aggregrate function:
'System.Collections.Generic.List<Models.Tag>' does not contain a
definition for 'Aggregrate' and no extension method 'Aggregrate'
accepting a first argument of type
'System.Collections.Generic.List<Models.Tag>' could be found (are you
missing a using directive or an assembly reference?)

Do you know what is wrong?

Thanks,
Miguel
Aug 21 '08 #3
On Aug 21, 11:56*pm, shapper <mdmo...@gmail.comwrote:
On Aug 21, 4:11*pm, Martin Honnen <mahotr...@yahoo.dewrote:
shapper wrote:
* * * * * * * * * * * * * *Tags = new List<Tag>(
* * * * * * * * * * * * * * *from pt indatabase.PostTags
* * * * * * * * * * * * * * *join t in database.Tags on pt.TagID
equals t.TagID
* * * * * * * * * * * * * * *where pt.PostID == p.PostID
* * * * * * * * * * * * * * *select t).ToString()
* * * * * * * * * * * * *}).SingleOrDefault();
Tags should be a string with CSV values. So I added it the ToString()
at the end. However it is returning a List.
What am I doing wrong?
If you want a string with comma separated values then you could try
* *Tags = * * * * * * * * * * * * * **(from pt in database.PostTags
* * * * * * * * * * * * * * * join t in database.Tags on pt.TagID
equals t.TagID
* * * * * * * * * * * * * * * where pt.PostID == p.PostID
* * * * * * * * * * * * * * * select t).Aggregrate((a, b) =a + "," + b)
--
* * * * Martin Honnen --- MVP XML
* * * *http://JavaScript.FAQTs.com/

I get an error on the Aggregrate function:
'System.Collections.Generic.List<Models.Tag>' does not contain a
definition for 'Aggregrate' and no extension method 'Aggregrate'
accepting a first argument of type
'System.Collections.Generic.List<Models.Tag>' could be found (are you
missing a using directive or an assembly reference?)

Do you know what is wrong?

Thanks,
Miguel
I think Aggregate does not work with Linq. Any idea of how to solve
this?

Thanks,
Miguel
Aug 22 '08 #4
shapper wrote:
I think Aggregate does not work with Linq. Any idea of how to solve
this?
It works fine for me:

List<stringlist1 = new List<string>() { "1", "2", "3" };
Console.WriteLine(list1.Aggregate((a, b) =a + "," + b));

Can you post the definitions of the types you are using?
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 22 '08 #5
Martin Honnen wrote:
shapper wrote:
>I think Aggregate does not work with Linq. Any idea of how to solve
this?

It works fine for me:

List<stringlist1 = new List<string>() { "1", "2", "3" };
Console.WriteLine(list1.Aggregate((a, b) =a + "," + b));

Can you post the definitions of the types you are using?
Youor query runs in memory, his in the DB. The 'Aggregate' extension
method doesn't have a DB equivalent so every Linq to <dbprovider will
give up on it, unless it can convert it to an inmemory method call,
which isn't the case with Aggregate stuff.

TS should pass the nested query result to a method, concat there, and
return teh result and use that as a value.

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#)
------------------------------------------------------------------------
Aug 23 '08 #6

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.). ...
4
by: Arthur Dent | last post by:
Hello all, I am trying to figure out how to do something in LINQ, IF I can even do it in LINQ. Online samples and such for LINQ is still a bit on the sketchy side. Here is what I want to...
8
by: Andy | last post by:
Hi, I'm trying to add a where clause to my query: List<stringtypes = new List<string>(); types.Add( "A" ); types.Add( "B" ); query = query.Where( c =types.Contains( c.Type ) );
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...
4
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and...
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
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);
1
by: Dean Slindee | last post by:
VS2008, .NetFramework 3.5 SP1: I have built a LINQ data access layer project. When the LINQ data context was built over an existing SQL2005 database, the connection string for that database was...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.