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.Sele ct(o =>
o.OptionID = id)).SingleOrDe fault;
I am not sure if this is the right way but I am getting an error
anyway:
Cannot convert method group 'SingleOrDefaul t' to non-delegate type
'MyApp.Models.P oll'. 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 3037
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.Sele ct(o =>
o.OptionID = id)).SingleOrDe fault;
I am not sure if this is the right way but I am getting an error
anyway:
Cannot convert method group 'SingleOrDefaul t' to non-delegate type
'MyApp.Models.P oll'. 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.Sele ct(o =>
o.OptionID = id)).SingleOrDe fault();
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)).SingleOrDe fault();
--
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 a new column of type boolean
|
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.).
Assume I want to select rows from a database and check whether a specific
column contains keywords from a list of keywords. The following works just
fine:
List<stringsearchTerms = new List<string>() { "Maria",
"Pedro" };
|
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 programming, just with a
different data getting process...
|
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 find which items in A do not exist in B then:
|
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 data
that would be used to filter the dataset we return. STANDARD STUFF.
Below is simplified version (not compete) of how we solved this with
ADO using javascript on the client to build a where clause that we
would use on our SQL SELECT...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |