LINQ - Select records

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have 3 SQL tables:

[Tags] > TagId, TagText
[Posts] > PostId, TagId, ...
[Files] > FileId, TagId, ...

I need to, using LINQ, select all records in Tags, including the
columns TagId and TagText, but adding a new column of type boolean
which is True if the tag is associated to a Post OR to a File, i.e.,
if the TagId exists in Posts or Files.

How can I do this?

Thanks,
Miguel
 
Miguel,

Have you used the new O/RM tool within Visual Studio 2008 to create the db
context?

You should then be able to express:

var query = from t in db.Tags
select new
{
TagId = t.TagId,
TagText = t.TagText,
hasPosts = t.Posts > 0,
hasFiles = t.Files > 0
};

This is supposed to work because LINQ to SQL exposes the foreign key
relationship as a collection at the object level.

Please lest me/us know how it goes!

Best regards
-Ralf

http://www.24100.net
 
Did it work? Any feedback?


Ralf Rottmann said:
Miguel,

Have you used the new O/RM tool within Visual Studio 2008 to create the db
context?

You should then be able to express:

var query = from t in db.Tags
select new
{
TagId = t.TagId,
TagText = t.TagText,
hasPosts = t.Posts > 0,
hasFiles = t.Files > 0
};

This is supposed to work because LINQ to SQL exposes the foreign key
relationship as a collection at the object level.

Please lest me/us know how it goes!

Best regards
-Ralf

http://www.24100.net


shapper said:
Hello,

I have 3 SQL tables:

[Tags] > TagId, TagText
[Posts] > PostId, TagId, ...
[Files] > FileId, TagId, ...

I need to, using LINQ, select all records in Tags, including the
columns TagId and TagText, but adding a new column of type boolean
which is True if the tag is associated to a Post OR to a File, i.e.,
if the TagId exists in Posts or Files.

How can I do this?

Thanks,
Miguel
 
Did it work? Any feedback?


Have you used the new O/RM tool within Visual Studio 2008 to create the db
context?
You should then be able to express:
var query = from t in db.Tags
select new
{
TagId = t.TagId,
TagText = t.TagText,
hasPosts = t.Posts > 0,
hasFiles = t.Files > 0
};
This is supposed to work because LINQ to SQL exposes the foreign key
relationship as a collection at the object level.
Please lest me/us know how it goes!
Best regards
-Ralf

shapper said:
Hello,
I have 3 SQL tables:
[Tags] > TagId, TagText
[Posts] > PostId, TagId, ...
[Files] > FileId, TagId, ...
I need to, using LINQ, select all records in Tags, including the
columns TagId and TagText, but adding a new column of type boolean
which is True if the tag is associated to a Post OR to a File, i.e.,
if the TagId exists in Posts or Files.
How can I do this?
Thanks,
Miguel

Hello,

Sorry, I was out of work. I didn't try it yet.

I was trying to put this in a LINQ Data Source.

This is something I am not sure. Is it possible to use any LINQ query
in a LINQ Data Source?

Thanks,
Miguel
 
Back
Top