mysql linq any查询_c# – LINQ查询中的MySqlDateTime

我正在尝试将

MySqlDateTime对象与另一个MySqlDateTime对象进行比较,每个对象来自两个不同的表.我试图在LINQ查询中做所有这些,例如:

var prodRowFindQuery =

from x in production.AsEnumerable()

where x.Field("date") == row.Field("date") &&

x.Field("device_id3") == row.Field("device_id3")

select x;

这给了我一个编译器错误:

运算符’==’不能应用于’MySql.Data.Types.MySqlDateTime’和’MySql.Data.Types.MySqlDateTime’类型的操作数

那么我试试这个:

var prodRowFindQuery =

from x in production.AsEnumerable()

where x.Field("date").ToString() == row.Field("date").ToString() &&

x.Field("device_id3") == row.Field("device_id3")

select x;

现在它编译,但我得到一个运行时错误:

指定演员表无效.

堆栈跟踪:

IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DataTableComparer.CompareTables.AnonymousMethod__0(System.Data.DataRow x = {System.Data.DataRow}) Line 34 C#

System.Core.dll!System.Linq.Enumerable.WhereEnumerableIterator.MoveNext() + 0x9c bytes

IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DataTableComparer.CompareTables(System.Data.DataTable aggregate = {System.Data.DataTable}, System.Data.DataTable production = {System.Data.DataTable}) Line 39 + 0x8b bytes C#

IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DbTransferWindowViewModel.CopyTestReliability() Line 177 + 0x94 bytes C#

IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DelegateCommand.Execute() Line 78 + 0x1f bytes C#

IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DelegateCommand.System.Windows.Input.ICommand.Execute(object parameter = null) Line 158 + 0xa bytes C#

PresentationFramework.dll!System.Windows.Controls.Button.OnClick() + 0xaf bytes

PresentationFramework.dll!System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e) + 0x117 bytes

PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) + 0x56 bytes

PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) + 0x270 bytes

PresentationCore.dll!System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject sender = {System.Windows.Controls.Button}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, System.Windows.RoutedEvent newEvent) + 0x183 bytes

PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) + 0x56 bytes

PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) + 0x270 bytes

PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {System.Windows.Controls.Button}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}) + 0x14e bytes

PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}) + 0x64 bytes

PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() + 0x431 bytes

PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) + 0xfd bytes

PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel) + 0x410 bytes

PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd = 396436, MS.Internal.Interop.WindowMessage msg = WM_LBUTTONUP, System.IntPtr wParam = 0, System.IntPtr lParam = 34472260, ref bool handled = false) + 0x388 bytes

PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x7c bytes

WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x14a bytes

WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x80 bytes

WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x5e bytes

WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate method, object args, int numArgs, System.Delegate catchHandler = null) + 0x47 bytes

WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) + 0x2bc bytes

WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) + 0x140 bytes

[Native to Managed Transition]

[Managed to Native Transition]

WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) + 0x112 bytes

PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) + 0x17a bytes

PresentationFramework.dll!System.Windows.Application.Run() + 0x67 bytes

IthacaDbTransferUtil.exe!IthacaDbTransferUtil.App.Main() + 0x77 bytes C#

[Native to Managed Transition]

[Managed to Native Transition]

Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x5a bytes

mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x285 bytes

mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x9 bytes

mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x57 bytes

mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x51 bytes

[Native to Managed Transition]

我试过的另一个例子:

var prodRowFindQuery =

from x in production.AsEnumerable()

where Convert.ToDateTime(x.Field("date")) == Convert.ToDateTime(row.Field("date")) &&

x.Field("device_id3") == row.Field("device_id3")

select x;

仍然会引发运行时错误:

指定演员表无效.

另一个例子:

var prodRowFindQuery =

from x in production.AsEnumerable()

where x.Field("date") == row.Field("date") &&

x.Field("device_id3") == row.Field("device_id3")

select x;

相同的运行时错误:

指定演员表无效.

有人说“日期”不是MySqlDateTime类型,为了好玩,这里的证明是:

var prodRowFindQuery =

from x in production.AsEnumerable()

where x.Field("date") == row.Field("date") &&

x.Field("device_id3") == row.Field("device_id3")

select x;

运行时异常:

无法将类型为“MySql.Data.Types.MySqlDateTime”的对象强制转换为“System.String”.

我尝试过其他一些东西,对我来说没什么用.

任何帮助将不胜感激,

问候,

凯尔

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值