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 1 3017
shapper wrote:
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();
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: shapper |
last post by:
Hello,
I have 3 SQL tables:
TagId, TagText
PostId, TagId, ...
FileId, TagId, ...
I need to, using LINQ, select all records in Tags, including the
columns TagId and TagText, but adding...
|
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.).
...
|
by: Andy B |
last post by:
Just wondering why linq is more useful than datasets? The stuff I do doesn't
seem to be too complicated to use linq with it. If I did use linq with it
now, I would be doing almost the exact same...
|
by: shapper |
last post by:
Hello,
I have two Lists:
A = {ID, Name} = { (Null, John), (Null, Mary), (Null, Andrew), (Null,
Peter) }
B = {ID, Name} = { (1, John), (2, Robert), (3, Angela), (4, Andrew) }
I want to...
|
by: shapper |
last post by:
Hello,
I have the following LINQ:
List<Tagtags = (from t in
database.Tags
select t).ToList();
I need to restrict my results and for that I have two parameters:
StartWidth and N
|
by: Plissskin |
last post by:
I need to create an "ad-hoc" filtering page in a web app we are
building. The page would display a number of drop down lists, text
boxes, and radio lists and allow the user to select (enter) some...
|
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
|
by: shapper |
last post by:
Hello,
Is it possible to multiply all Prices in a List<Productby 1.1 using
Linq?
Product has a property named Price.
Thanks,
Miguel
|
by: hrishy |
last post by:
Hi
Will LINQ be ported to Python ?
regards
Hrishy
|
by: shapper |
last post by:
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 {
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |