score:2
In .NET 3.5, there exists a static Enumerable
existing in System.Linq
, which contains extension methods for manipulating IEnumerable
s - this is not what you want to (or clearly can) return. Change it to IEnumerable
, which is the non-generic enumerable class (and what I think you intend), and all should work fine.
Even better, use the generic version of IEnumerable
, as such:
public static IEnumerable<StuffDepartman> LoadDataByName(string name)
{
var stuffs = (List<StuffDepartman>)HttpContext.Current.Session["Stuffs"];
return (from s in stuffs where s.Name == name select s.Name);
}
Also, note that you don't need the call to AsEnumerable
before returning, since List<T>
implements IEnumerable<T>
, and the former can be implicitly casted to the latter. The =
needed to be changed to ==
, since you want to use the equality rather than assigment operator here. The other changes are just tidying up.
score:1
System.Linq.Enumerable
is a static class with a bunch of extension methods defined on it. You perhaps meant to return IEnumerable<string>
instead.
score:0
Enumerable is a static class, what you want to do is return an IEnumerable:
public static IEnumerable<string> LoadDataByName(string name)
{
//do stuff
}
I'm assuming s.Name in your example is a string, which is why the method should return IEnumerable<string>. If it's another type, then change it to that type....
EDIT: Ok, I guess it's not a string. Change it to:
public static IEnumerable<StuffDepartman> LoadDataByName(string name)
{
//do stuff
}
Source: stackoverflow.com
Related Articles
- Return Enumerable value from Class in linq?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- LINQ to Entities - How to return a single string value from entity
- How to Deal With Dapper return Key Value pair with Dynamic from LINQ
- creating Linq to sqlite dbml from DbLinq source code
- return a class directly from a linq query
- Linq return WhereEnumerableIterator from Dictionary value matches?
- How can I return a list or enumerable of rows where column value has changed with Linq
- how to return a value from a LINQ statement
- LINQ - Return Value From Field With A Max Value if No Rows Found
- Can't add a new record with an integer value into database by using linq from code C#
- Can I receive both the return value and resultset from a procedure using Linq to sql?
- Is it possible to return a return value and a result set from a stored procedure using LINQ
- LINQ function to return list but compiler says function doesn't return a value on all code path
- how to use linq to return a value from 4 tables
- How can I return a single value integer from Linq from an array of objects that have other nested values
- I get a query string as return value from LINQ to SQL and WCF Services and no concrete value
- How do i return a value from LINQ into a parameter? C#
- returning multiple class model data from linq in list via return method in C#
- Access to the return value from the database by linq
- How to return value from 2 tables in one linq query
- c# Linq or code to extract groups from a single list of source data
- LINQ return value conversion failed from string to int
- How to return sum value from using group by, having and sum by using LINQ in C#
- Using Linq to Order by Descending from a Method Return value
- How to built a dictionnary from linq query with Id as Key and Data Class as Value in c#?
- Find a certain value from a source collection in a target collection of different type with linq
- Returning a custom list class type from LINQ Query - return same type going in that is coming out
- Using C# Linq find and return a string value from a multi-level data store
- How can I get LINQ to return the object which has the max value for a given property?
- FirstOrDefault behavior directly in LINQ statement
- Self Join or Inner Query in a table with Linq to SQL
- dynamic filters in asp.net mvc 4
- testing field values of an anonymous type in a generic way
- How convert to linq request?
- Select returning a collection of true/false values, not a list of objects matching criteria
- Retrieving Database Schema Linq to SQL VB.Net
- Elegant way to filter a complex array of objects
- Check string pattern in LINQ query
- Visual Studio Code Analysis Rule - "Do not expose generic lists"
- AngleSharp - Find innermost nested tables
- Like search for datetime fields using dynamic lambda expression
- Strange value in LINQ query result
- Entity Framework select by child table last state
- Filtering a nested list and out put as tree
- Linq Sorted Groupby and Orderby fields
- Let Query syntax in Method Syntax?
- How do I combine the keys and values of a Dictionary into one List using LINQ?
- finding min and maxin list using LINQ and DBNulls
- LINQ select distinct set and retrive different column