score:0
if its linq to sql you cant since it tries to render that to real sql. try to cast the persons to another object class of your own and then it will be linq to object and there it will work. i had this issue a few times, i played with it a little bit until it worked.
btw i think one of the linq extensions is looking for an icomparable, so worse case you can just implement one
score:0
i will give you a one-liner which "could" work, but please provide the exception as well.
var query = _db.persons.asenumerable().orderby(p => decrypt(p.name));
your problem is probably, but it is hard to know since we are not given the exception, that you are trying to get your database to execute decrypt
which is not possible. the added tolist()
just enumerates, ie fetches the data from database in this case, and then we can order in memory.
you won't get paging to work the way you want since the database cannot execute the query.
score:1
you need to actually figure out why is the paging not working. it's possible to create custom sql function and let decrypt work. for that, you need to create sql function decrypt that does the work.
this is simple example:
(sql part)
create function reversecustname(@string varchar(100))
returns varchar(100)
as
begin
declare @custname varchar(100)
-- implementation left as exercise for users.
return @custname
end
and linq part
[function(name = "dbo.reversecustname", iscomposable = true)]
[return: parameter(dbtype = "varchar(100)")]
public string reversecustname([parameter(name = "string",
dbtype = "varchar(100)")] string @string)
{
return ((string)(this.executemethodcall(this,
((methodinfo)(methodinfo.getcurrentmethod())),
@string).returnvalue));
}
see this for more information: http://msdn.microsoft.com/en-us/library/bb386973(v=vs.110).aspx
Source: stackoverflow.com
Related Query
- How to call custom method in linq query
- Call a custom method in linq query
- Call class method inside the Linq Query
- Call Method from Linq query
- Linq to entity - Call user defined method from query
- How to call a method in the where clause of a LINQ query on a IQueryable object
- Call a method inside LINQ Query
- Custom Method in LINQ to SQL query
- How to specify a custom method in a LINQ query (C# Entity Framework)
- Integrating custom method into LINQ to Entities query
- .NET LINQ Call Method with Out Parameters Within Query and use Out Values
- Calling a custom method in LINQ query
- Call method on LINQ query results succinctly
- C# LINQ - Edit my query to call a method on the result
- Custom Method in LINQ Query
- How do I call a method from within a linq query that is retrieving from an Entity Framework model
- How to call a method within .Select in Linq query without having to write select twice?
- Entity Framework LINQ Query using Custom C# Class Method - Once yes, once no - because executing on the client or in SQL?
- Call method from within Linq query
- LINQ query to call instance method
- How to call a local method from the linq query
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- LINQ - Query syntax vs method chains & lambda
- Ambiguous call when using LINQ extension method on DbSet<T>
- .NET LINQ query syntax vs method chain
- Calling a method inside a Linq query
- How to retrieve last 5 records using LINQ method or query expression in C#
- GroupBy with linq method syntax (not query syntax)
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- How to await a method in a Linq query
More Query from same tag
- Which LINQ query is more effective?
- Linq to NHibernate - select count problem
- Load list with linq to xml
- LINQ Query - Only get Order and MAX Date from Child Collection
- How do I get values of Linq Expression
- Insert values in col1 of list 1 from col 2 of list 2 based on a common column
- pagination in asp.net mvc
- Get value from Database to Linq where clause
- WHERE is not being included in the LINQ-query
- How To Update Data With Linq By Attach Method
- Divide a large IEnumerable into smaller IEnumerable of a fix amount of item
- Linq duplicate/copy the whole record
- Better LINQ query to set value of property based on condition
- Join string with same property using LINQ
- Help with sql to linq conversion
- LINQ to dictionary
- How to check if a name is contained in another collection
- Get list of elements where there are two records
- c#: New string array from two, where one has strings the other contains?
- Linq<string> 2 lists select without having to foreach
- Linq Join and/or Filter on DateTime evaluation?
- Retrieve inactive clients by LINQ
- Distinct Dictionary Using LINQ
- LINQ left outer join with exclusion
- How do we use a LINQ query on a Dictionary with a nested object?
- linq where statement with OR
- Filtering On ThenInclude Three Nested Levels down
- How to group by with left join by multiple columns using linq and get count of grouped records?
- Get Alphabetical List Of Items in Collection Using Lambda/Linq?
- Dynamic LINQ queries for a web API