Linq. Select.

S

shapper

Hello,

I have two tables:
Polls > PollID, Question
Options > OptionID, Answer

Given a OptionID I want to get the poll to which the Option "Belongs":
Poll poll = database.Polls.Select(p => p.Options.Select(o =>
o.OptionID = id)).SingleOrDefault;

I am not sure if this is the right way but I am getting an error
anyway:
Cannot convert method group 'SingleOrDefault' to non-delegate type
'MyApp.Models.Poll'. Did you intend to invoke the method?

I have all relations between tables well defined and I used LinqToSQL
classes.

How should I do this?

Thanks,
Miguel
 
M

Martin Honnen

shapper said:
I have two tables:
Polls > PollID, Question
Options > OptionID, Answer

Given a OptionID I want to get the poll to which the Option "Belongs":
Poll poll = database.Polls.Select(p => p.Options.Select(o =>
o.OptionID = id)).SingleOrDefault;

I am not sure if this is the right way but I am getting an error
anyway:
Cannot convert method group 'SingleOrDefault' to non-delegate type
'MyApp.Models.Poll'. Did you intend to invoke the method?

I have all relations between tables well defined and I used LinqToSQL
classes.

How should I do this?

First of all, SingleOrDefault is a method and methods are called this way:

Poll poll = database.Polls.Select(p => p.Options.Select(o =>
o.OptionID = id)).SingleOrDefault();

However I don't think you want a Select, you want a Where e.g.

Poll poll = database.Polls.Where(p => p.Options.Any(o =>
o.OptionID = id)).SingleOrDefault();
 

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


Top