score:0
project out the property you want with .select(x => x.myprop);
return fatcaquestionaires.select(x => x.questionaire).tolist();
score:1
change select
to where
as i mentioned in my comment. select
will just return a bool value for every entry's evaluation base on your lambda expression.
so you end up with a list<bool>
var fatcaquestionaires = context.fatcaquestionaires
.where(p => p.contactid == contactid)
.select(q=>q.questionaire).tolist();
return fatcaquestionaires;
score:2
what you have written looks like it will return a list of booleans and not compile. what you need is a combination of a where
clause and a select
clause.
return context.fatcaquestionaires
.where(p => p.contactid == contactid)
.select(p => p.questionaire).tolist();
where()
is what limits the factaquesntionaires, and select()
is where you choose the property to return. you can also write it like this:
return (from p in context.fatcaquestionaires
where p.contactid == contactid
select p.questionaire).tolist();
score:4
you almost have it. select
invokes a transformation function, so it is just making a list of bool
. you need a where
clause to do the filtering, and then a select
.
var fatcaquestionaires = context.fatcaquestionaires
.where(p => p.contactid == contactid)
.select(p => p.quentionaire);
return fatcaquestionaires.tolist();
score:6
using linq, first you can do a where
filtering the desired rows, and then select
to projecting only questionaire properties.
try this
return context.fatcaquestionaires
.where(p => p.contactid == contactid)
.select(p => p.questionaire)
.tolist();
Source: stackoverflow.com
Related Query
- List or Array of String Contain specific word in Html Source Code
- Return list of string
- Linq to NHibernate return entities whose name starts with contents of string list
- linq query to return a string from a list
- Return a list of string using LINQ through a loop of conditionals
- Return a list of Directory (Folder) names that match a partial string
- Return the number of times a string occurs as a property in a list of custom objects
- LINQ function to return list but compiler says function doesn't return a value on all code path
- How to convert a list of anonymous object to string array using linq for return using Json Result in ASP.NET MVC
- Return list of string from list nested in a list
- C# Return true if string is different from any of the string in a list of strings using LINQ
- c# Linq or code to extract groups from a single list of source data
- linq return all items where string field is like any in a list of strings
- C# Linq to check if the given list of string is available in either (oldNumber and newNumber) of the Column and return only the matched cell value
- Match a comma delimited string to an integer list using linq and return the new objects
- Check if list contains element that contains a string and get that element
- How to check if all list items have the same value and return it, or return an “otherValue” if they don’t?
- LINQ query to return distinct field values from list of objects
- C# - code to order by a property using the property name as a string
- Using Linq to return a Comma separated string
- Return list using select new in LINQ
- Return list of specific property of object using linq
- Is there a LINQ function for getting the longest string in a list of strings?
- C# Select elements in list as List of string
- compare two list and return not matching items using linq
- Join together all items of a list in an output string in .NET
- LINQ return items in a List that matches any Names (string) in another list
- Using LINQ to convert a list to a CSV string
- How to return empty string if an object is null?
- Replace string values in list
More Query from same tag
- MongoDb driver c# query optimization
- Clean some properties value in List with Linq based on a value of the list
- How do I resolve multiple linq queries in one operation without using a base query?
- Sort Class List by specific Variable
- Replacing a foreach with a linq statement
- EF5 code first datetime2, building a linq expression
- Problems with Let semantics in Linq-to-Objects and Linq-to-XML
- Map List by Linq Expression
- How can i have a linq result set returned as a custom type
- Extension method returning lambda expression through compare
- how to create a 'live' collection that's the concat/union/whatever of 2 (or more) other collections?
- Where Clause in LINQ with IN operator in Vb
- telerik expression editor - change return type
- Reseed SQL server statement throwing error Incorrect Syntax near
- Common Linq / Standard Query Operator mistakes/mis-steps?
- Convert an unit -> unit to Action
- Linq join with record of second table
- I have an IQueryable with WHERE IN (ids). Can ToList() return the same order as ids?
- linq `from` clauses between generic and non-generic collections?
- Database connections (best practices)
- where Clause in Asp.net is returning null exception in the code below
- How to display the collection in the library dynamically Highcharts - Bind collection with Highcharts in MVC
- Adding custom value in a LINQ join
- SSRS Simple WHERE Clause as expression
- XElement add node on specific position not working as expected
- Reactive Extension - Observable.FromEvent typecast conversion
- Find difference from IList<string[]> one and IList<string[]> two using Linq operation
- randomize Select do not work
- System.Xml.Linq.XDocument' is defined in an assembly that is not referenced
- EntityFramework using linq is slow