score:7
you can only use the core extension methods and clr methods defined for your ef provider when using entity framework and queries on iqueryable<t>
. this is because the query is translated directly to sql code and run on the server.
you can stream the entire collection (using .toenumerable()
) then query this locally, or convert this to a method that is translatable directly to sql by your provider.
that being said, basic bitwise operations are supported:
the bitwise and, or, not, and xor operators are also mapped to canonical functions when the operand is a numeric type.
so, if you rewrite this to not use a method, and just do the bitwise operation on the value directly, it should work as needed. try something like the following:
public list<album> getvisiblealbums(int accesslevel)
{
return rep.find<album>(a => (a.accesslevel & accesslevel > 0)).tolist();
}
(i'm not sure exactly how your current extension method works - the above would check to see if any of the flags come back true, which seems to match your statement...)
score:2
there are ways to change the linq query just before ef translates it to sql, at that moment you'd have to translate your ''foreign'' method into a construct translatable by ef.
see an previous question of mine how to wrap entity framework to intercept the linq expression just before execution? and mine efwrappablefields extension which does just this for wrapped fields.
score:10
i realize this already has an accepted answer, i just thought i'd post this in case someone wanted to try writing a linq expression interceptor.
so... here is what i did to make translatable custom extension methods: code sample
i don't believe this to be a finished solution, but it should hopefully provide a good starting point for anyone brave enough to see it through to completion.
Source: stackoverflow.com
Related Query
- Workarounds for using custom methods/extension methods in LINQ to Entities
- F# Linq extension methods for custom type using linq query
- Using LINQ to Entities extension methods for more than one entity type
- Using custom methods that return IQueryable in the LINQ to entities
- Using Custom Extension Methods Inside Linq Query
- Using Custom Extension Methods inside LinQ (Compare two strings)
- How do you perform a left outer join using linq extension methods
- Extension method for IQueryable left outer join using LINQ
- Nice, clean cross join in Linq using only extension methods
- How to: Use async methods with LINQ custom extension method
- How to reuse a linq expression for 'Where' when using multiple source tables
- extend linq to entities to recognize custom methods
- LINQ extension methods not available for EnumerableRowCollection<TRow>
- What is the C# extension methods equivalent for this Linq query?
- Resharper Convert foreach to LINQ using extension methods
- C# .Net 3.5 Code to replace a file extension using LINQ
- Generic Extension method for LINQ JOIN using 2 columns
- Using LINQ query result for data source for GridControl c#
- How do I find max date for matching entities by entity.ids using linq
- how to execute custom function for each item later using linq deferred execution?
- Using LINQ to query/subquery multiple methods (Quartz.NET example for groups, jobs, and triggers)
- How to write this code using the Linq Extension Method-Syntax?
- Code Rewite for tuple and if else statements by using LINQ
- Making thing more succint using linq to entities for inner joins
- Entity Framework Core: Custom Linq methods for querying view models from DbContext
- Why the extension method of where for LINQ in this code would print out a single number while it shouldn't print anything at all?
- source code for LINQ 101 samples
- Linq extension method equivalent for that code in VB.NET
- Linq to Entities - using group by for many-to-many tables
- How to make types match in LINQ to Entities when using .GroupJoin extension with multiple conditions?
More Query from same tag
- Cannot convert lambda expression to delegate type
- Is ORM (Linq, Hibernate...) really that useful?
- Reduce linq query for filtering
- How this query works?
- lambda expression in boo
- C# - LINQ query returns null to table and throws exception
- How to call a lambda using LINQ expression trees in C# / .NET
- C# LINQ select until amount >= 0
- LINQ expression could not be translated. client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList'
- Help Refactoring Entity Framework 4 Query
- Function predicate to string
- Problem in searching with linq using vb.net
- Dynamic LINQ, Select function, works on Enumerable, but not Queryable
- sql equivalent linq expression
- Linq with custom base collection
- Why does LINQ not cache enumerations?
- What actually happens when using async/await inside a LINQ statement?
- Query to remove last result using LINQ to XML
- Linq to Dynamics - compare two properties in where clause
- Is it possible to use a string for a LINQ query expression?
- Exclude LINQ results from one query in another LINQ query
- Group by clause vs. Distinct()
- Is there really multiple iterations of an IEnumerable in this code?
- How to do Linq GroupJoin on self to fill children/parent properties?
- How can I make my login session faster?
- LINQ joining values from different classes
- How to Implement GetEnumerator method for class that implements IEnumerable<IEnumerable<T>>
- Get each item from a list and compare it with a different one
- Getting inappropriate json data struture
- Invalid column name when published on azure