LINQ - Select records

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
 
R

Ralf Rottmann

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
 
R

Ralf Rottmann \(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
 
S

shapper

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

XML and SQL database 3
Linq. Select 1
Circular Reference. I really need help ... thanks. 4
Linq. Delete Record 2
Linq > Group 2
Delete Record using Linq 3
Delete Record with LINQ 3
Linq. Count. 3

Top