score:2
Remove the parameter from your method and make the expression accept two parameters:
public static Expression<Func<MyModel, DateTime, bool>> IsDateOf
= (MyModel p, DateTime d) => p.StartedAt.AddSeconds(p.UtcOffset) == d.Date;
Note I have made it a static field, not a method. Then in your LINQ expression, you need to invoke it:
MyModel.IsDateOf(result.entry, result.rec.DayOf)
If you don't make it a field (or property), you have to first invoke the method to get the expression; then you need to invoke the expression:
MyModel.IsDateOf()(result.entry, result.rec.DayOf)
Which, in my opinion, looks weird.
Source: stackoverflow.com
Related Query
- How can I extract DbFunctions/SqlFunctions call into a resuable extension/method with EntityFramework 6.2?
- How can I call local method in Linq to Entities query?
- How can I write a generic extension method for converting a delimited string to a list?
- How to call extension method "ElementAt"of List<T> with reflection?
- How can I simplify Linq extension method invokation using reflection?
- How can I combine this code into one or two LINQ queries?
- How can I turn this 12-line method into a 1-line LINQ expression?
- How can I call a method from within a LINQ expression?
- How can I code numerous MIN functions into one LINQ to DataSet query
- How can I convert two methods into a single method to increase efficiency?
- How can I pass different types of list<T> into a method for grouping by similar fields
- How to code an Or extension method
- How can I call method from all elements in list array (linq list) C#
- How can I use Where<T> extension method when T is unknown at compile time
- How can I use this extension method in a linq to entities query using query syntax?
- How can I make Linq extension method available for the entities?
- How can i convert this code snippet into LINQ format?
- How can i call from another method a linq?
- how to translate method call into lambda expression
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Ambiguous call when using LINQ extension method on DbSet<T>
- How do I invoke an extension method using reflection?
- How to implement left join in JOIN Extension method
- How can I use continue statement in .ForEach() method
- How can I split an IEnumerable<String> into groups of IEnumerable<string>
- Why does C# compiler create private DisplayClass when using LINQ method Any() and how can I avoid it?
- Why can't I call an extension method from a base class of the extended type?
- How to get the sum of list of shorts using the extension method Sum()?
- Using Linq's Where/Select to filter out null and convert the type to non-nullable cannot be made into an extension method
- How to create a dynamic LINQ join extension method
More Query from same tag
- LINQ intersect() method
- Retrieving the username from MembershipUser for a join query
- Select ID from Table where it does not match ID in another table
- Checking for default value when using Linq, var and FirstOrDefault()?
- NHibernate IQueryable doesn't seem to delay execution
- Combine Linq join
- LINQ - Cannot implicitly convert type with custom data model list property
- How to get the last record
- LINQ to XML and LINQ to Objects syntax
- linq query with join returning incorrect values/associations
- Linq Expression to String
- Entity Framework and mapping relationships: What's the point?
- Get collection of class instance with property combinations
- How to use Delete all functionality in Linq
- Count of duplicate items in a C# list
- Linq IEnumerable Extension Method - How to improve performance?
- LINQ Where clause throws casting exception from string to Guid even though comparison only contains Guids
- Adding Linq method with column rename results to viewModel
- Order by descending by row field in query
- EF Linq- Dynamic Lambda expression trees
- LINQ not returning the right ROW of data
- Query sub collection - majority mutual ids that contains in list
- Querying many-To-many relationship with a list of parameters
- XML to dropdown list using LINQ
- 'int' does not contain a definition for 'Contains' and the best extension method overload 'Queryable.Contains
- Cassandra: Argument types do not match
- How to use OrderBy in Linq
- Are those 2 linq equivalent?
- LINQ count field of selected objects
- How to invoke Expression<Func<Entity, bool>> against a collection