LINQ to Entities中的LastIndexOf [英] LastIndexOf in LINQ to Entities

查看:89
本文介绍了LINQ to Entities中的LastIndexOf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LINQ to Entities从MSSQL数据库中获取元素,我需要将它们按字符串的最后一个索引排序:

I'm using LINQ to Entities to fetch elements from a MSSQL data base and I need them sorted by the last index of a string:

var data = db.GetEntities().
           OrderBy(e=>e.StringProperty.LastIndexOf("Foo")).ToList()

但是,LINQ to Entities不支持LastIndexOf.我曾尝试搜索类似的问题,但发现的只是 this 不能解决我的问题(订购).在MSDN上搜索没有任何结果.

However, LINQ to Entities does not support LastIndexOf. I've tried searching for similar questions but all I've found was this which does not address my issue (ordering). Searching on MSDN did not yield any results.

使用LINQ to Entities完成此操作的最简单方法是什么(我不想在ToList())之后执行此操作.

What would be the simplest way to accomplish this using LINQ to Entities (I don't want to have to do this after the ToList()).

推荐答案

您可以尝试

OrderBy(e => e.StringProperty.Length - EntityFunctions.Reverse(e.StringProperty).IndexOf("ooF"))

我认为支持ReverseIndexOf.

这篇关于LINQ to Entities中的LastIndexOf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆