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

Linq. Select.

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
Nov 13 '08 #1
1 3021
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/
Nov 13 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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...
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.). ...
7
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...
15
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...
2
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
6
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...
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
7
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
21
by: hrishy | last post by:
Hi Will LINQ be ported to Python ? regards Hrishy
2
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 {
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.