English 中文(简体)
Cannotsign Nullable <Int64> to Linq.Table.Max()?
原标题:Cannot assign Nullable<Int64> to Linq.Table.Max()?

我的方案有以下两条法典。 目标是将最高数目从价值领域退回。

MyDataContext context = new MyDataContext();
long? id = (long?)context.MyTable.Max(x => x.Value);

价值领域是表中的一个大领域。 该表还不能保证它包含各行,事实上这是我现在正在测试的情况。 我在试图这样做的时候,我无法说几句话。

第2行将无效作业除外。

不能将无效价值分配给具有类型系统的成员。 第64号是不可损耗的价值类型。

我尝试了几种不同的方式,但我无法做到这一点。 我显然不理解在C#中哪些类型的无效。

EDIT(溶解):

由于Chris的回答,我找到了我的问题和解决办法的实际原因。 由此可见,价值领域如此之少,但是由于Mlambda语中的x字面是一字不提的。 因此,我补充说,在Mlambda内部进行了检查,看看X是否无效,如果价值无效,我可以安全检查。

MyDataContext context = new MyDataContext();
long? id = context.MyTable.Max(x => x == null ? (long?)0 : (long?)x.Value);
最佳回答
问题回答

暂无回答




相关问题
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. ...

热门标签