Calling a method inside a Linq query

后端 未结 3 1146
攒了一身酷
攒了一身酷 2020-12-04 19:55

I want to insert into my table a column named \'S\' that will get some string value based on a value it gets from a table column.

For example: for each ID (a.z

3条回答
  •  死守一世寂寞
    2020-12-04 20:02

    You have to execute your method call in Linq-to-Objects context, because on the database side that method call will not make sense - you can do this using AsEnumerable() - basically the rest of the query will then be evaluated as an in memory collection using Linq-to-Objects and you can use method calls as expected:

    var q = (from a in v.A join b in v.B
            on a.i equals b.j
            where a.k == "aaa" && a.h == 0
            select new {T = a.i, Z = a.z })
            .AsEnumerable()
            .Select(x => new { T = x.T, S = someMethod(x.Z).ToString() })
    

提交回复
热议问题