English 中文(简体)
如何命令 在Linq query[引证]一个扼杀现场的愤怒
原标题:How to OrderBy an integer in a string field in a Linq query [duplicate]

我从一个行文中获得了一些数据,我可以随时改变图象。 我想对它进行分类,并以数字识别为依据加以控制。 问题是,APIC在扼杀现场而不是作为<条码>、/code>和《Linq条条码》在转换尝试上储存该编号。

myControl.DataSource = dataFromDB.OrderBy(o => int.Parse(o.StringHoldingAnInt));

准则给各实体并不承认Int32 Parse(系统)的方法。 这种方法不能转化为储存的表述。

<代码>Convert.ToInt32 >t t work 要么。

准则给各实体不承认Int32 ToInt32(系统)的方法。 这种方法不能转化为储存的表述。

由于价值相同,因此作为扼杀手套,因此,按此顺序排列如下:1、10、11、2、3。

最佳回答

这几乎是效率高的,因为你不利用数据库查询来过滤你的成果,但这将从根本上质疑所有数据,然后对客户进行过滤。

myControl.DataSource = dataFromDB.ToList().OrderBy(o => int.Parse(o.StringHoldingAnInt));
问题回答

Came up with a simple trick to fix this: First order by length and then normaly.

dataFromDB.OrderBy(o => o.StringHoldingAnInt.Length).ThenBy(o => o.StringHoldingAnInt)

这一切都是在非行进行的,并且是用于记忆的。

您可以将询问转换为一份清单:

var query = ...;
var list = query.ToList();

现在,你们可以通过改变价值观:

list.OrderBy(o => int.Parse(o.StringHoldingAnInt));

问题在于,你正在收回他们从数据库中得出的许多价值,然后由你下令。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签