score:-1
Accepted answer
internal list<int> getolddoctorsids()
{
return getdoctorsids((doctor) => doctor.age > 30);
}
internal list<int> getexpensivedoctorsids()
{
return getdoctorsids((doctor) => doctor.cost > 30000);
}
internal list<int> getdoctorsids(func<datarow, bool> condition)
{
var result = from datarow doctor in doctortable.rows
where condition(doctor)
select doctor.id
list<int> doctors = new list<int>();
foreach (int id in result)
{
//register getting data
database.logaccess("getolddoctorsid: " + id.tostring());
if (database.allowaccess(doctorstable, id))
{
doctors.add(id);
}
}
}
score:0
internal list<int> getolddoctorsids(func<doctor, bool> whereclause)
{
var result = doctortable.rows.where(d => whereclause(d)).select(d => d.id);
//etc...
}
score:0
getdoctorsids(doctor => doctor.cost > 30000);
score:3
internal list<int> getdoctorsids(predicate<datarow> doctorfilter)
{
var result = from datarow doctor in doctortable.rows
where doctorfilter(doctor)
select doctor.id
list<int> doctors = new list<int>();
foreach (int id in result)
{
//register getting data
database.logaccess("getolddoctorsid: " + id.tostring());
if (database.allowaccess(doctorstable, id))
{
doctors.add(id);
}
}
}
Source: stackoverflow.com
Related Query
- Two methods that differ only in LINQ where part - delegate?
- Why does LINQ treat two methods that do the "same" thing differently?
- Combining two LINQ queries that only their return result is different
- Find sub elements that differ in two collections in Linq
- How to match two Lists with only items that are different in Linq
- LINQ Query with dynamic where clause based on search criteria that is NOT part of the returned object
- How do I add a where clause to a field that is not part of the return set for LINQ query
- Trying to perform a a linq query that joins two tables, has a where clause, and groups the results
- Multiple WHERE Clauses with LINQ extension methods
- Using LINQ for an object that only has GetEnumerator()
- Nice, clean cross join in Linq using only extension methods
- two conditions checking in where clause using linq 2 entites
- Linq - How to select items from a list that contains only items of another list?
- Using only the year part of a date for a WHERE condition
- linq deferred execution when using locks in methods that return IEnumerable
- Using a LINQ Where query to get only some of the ConfigurationManager.ConnectionStrings
- How to modify only one or two field(s) in LINQ projections?
- LINQ query with two joins that worked in EF 6 gives error in EF 7
- Linq to compare two lists of objects where one object has several lists
- Comparing two collections with IEquatable while using only LINQ
- How to compare only date part with linq expression?
- using linq with join using two where on two tables
- Why is MigrationHistory causing Linq results to differ when specifying only a subset of columns?
- Using the magic of LINQ - How to call a delegate for each criteria that matches?
- Apply a linq expression of an object to a list of items where that object is a propery of an item (Wrapper)
- Fluent LINQ - Select a list of parents that contains a list of children where a subset of children are present
- Using LINQ to create pairs from two different list where the entries have same attribute
- How do I use LINQ to find 5 elements in a row that match one predicate, but where the sixth element doesn't?
- How to solve LINQ to Entity query duplication when the queries only differ by a property?
- Linq statement with two where clauses
More Query from same tag
- How to find duplicates of particular column in data table in C# and return the duplicate's row number as output
- linq2db find string in varchar field
- rewrite Linq 'to other format'
- C# LINQ .Any not working on DocumentDb CreateDocumentQuery
- LINQ: why does this query not work on an ArrayList?
- linq how to select a parent with a child collection that contains one or many of an array (or list) of values
- DocumentDb .NET Core SDK - IQueryable.OrderBy generates invalid query
- Convert Array of Strings to Comma Separated String with additional concatenation
- Detecting statically whether a linq expression is null
- C# Query MongoDb using linq and returning valid Json
- mvc razor linq statement which is including firstordefault and where clause
- System.InvalidCastException. OK... Where?
- Speeding up a linq query
- Get N tweets from list in twitter using linq2twitter
- Linq caching data values - major concurrency problem?
- add where clauses to linq query with generic column name
- How do I search for a specific value in a generic List in C#?
- Linq grouping into evenly divided groups
- Left Join in LINQ Query and ToList
- c# convert predicate between each other
- Get empty slot with lowest index from an array
- C# LINQ Remove multiple objects from a list in single execution
- Need help converting a nested SQL statement to LINQ
- Can't fetch Navigation Property in Entity Framework
- Linq syntax join and group
- Creating Collection of Class Object
- EF core Linq groupby and having sum count - could not be translated and will be evaluated locally
- ParameterExpression of type 'MyClass' cannot be used for delegate parameter of type 'System.Object'
- A dictionary where value is an anonymous type in C#
- SL Turn Hierarchical Data into Flat Data to Populate a DataGrid