C# LINQ查询中的MySqlDateTime

C# LINQ查询中的MySqlDateTime,c#,mysql,.net,datetime,casting,C#,Mysql,.net,Datetime,Casting,我试图将一个MySqlDateTime对象与另一个MySqlDateTime对象进行比较,每个对象来自两个不同的表。我试图在LINQ查询中完成所有这些,例如: var prodRowFindQuery = from x in production.AsEnumerable() where x.Field<MySqlDateTime>("date") == row.Field<MySqlDateTime>("d

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

        var prodRowFindQuery =
            from x in production.AsEnumerable()
            where x.Field<MySqlDateTime>("date") == row.Field<MySqlDateTime>("date") &&
                  x.Field<String>("device_id3") == row.Field<String>("device_id3")
            select x;
var prodRowFindQuery=
从生产中的x开始。AsEnumerable()
其中x.Field(“日期”)==行字段(“日期”)&&
x、 字段(“设备_id3”)==行字段(“设备_id3”)
选择x;
这给了我一个编译器错误:

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

那么我就试试这个:

        var prodRowFindQuery =
            from x in production.AsEnumerable()
            where x.Field<MySqlDateTime>("date").ToString() == row.Field<MySqlDateTime>("date").ToString() &&
                  x.Field<String>("device_id3") == row.Field<String>("device_id3")
            select x;
var prodRowFindQuery=
从生产中的x开始。AsEnumerable()
其中x.Field(“日期”).ToString()==行.Field(“日期”).ToString()&&
x、 字段(“设备_id3”)==行字段(“设备_id3”)
选择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<System.Data.DataRow>.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]    
ithacadbtranferutil.exe!IthacaDbTransferUtil.DataTableComparer.CompareTables.AnonymousMethod_uu0(System.Data.DataRow x={System.Data.DataRow})第34行C#
System.Core.dll!System.Linq.Enumerable.WhereEnumerableInterator.MoveNext()+0x9c字节
IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DataTableComparer.CompareTables(System.Data.DataTable聚合={System.Data.DataTable},System.Data.DataTable生产={System.Data.DataTable})第39行+0x8b字节C#
IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DbTransferWindowViewModel.CopyTestReliability()行177+0x94字节C#
IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DelegateCommand.Execute()行78+0x1f字节C#
IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DelegateCommand.System.Windows.Input.ICommand.Execute(对象参数=null)行158+0xa字节C#
PresentationFramework.dll!System.Windows.Controls.Button.OnClick()+0xaf字节
PresentationFramework.dll!System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e)+0x117字节
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate处理程序,对象目标)+0x56字节
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlerSiml(对象源,System.Windows.RoutedEventTargets参数,布尔重调)+0x270字节
PresentationCore.dll!System.Windows.UIElement.ReraiseEvents(System.Windows.DependencyObject发送器={System.Windows.Controls.Button},System.Windows.RoutedEventArgs={System.Windows.Input.MousebuttoneEventArgs},System.Windows.RoutedEvent newEvent)+0x183字节
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate处理程序,对象目标)+0x56字节
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlerSiml(对象源,System.Windows.RoutedEventTargets参数,布尔重调)+0x270字节
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject发送器={System.Windows.Controls.Button},System.Windows.RoutedEventTargets参数={System.Windows.Input.MousebuttonEventTargets})+0x14e字节
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs={System.Windows.Input.MousebuttoneEventArgs})+0x64字节
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStaginArea()+0x431字节
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport InputReport InputReport)+0xfd字节
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd,System.Windows.Input.InputMode模式,int时间戳,System.Windows.Input.RawMouseActions动作,int x,int y,int wheel)+0x410字节
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字节
PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd,int msg,System.IntPtr wParam,System.IntPtr lParam,ref bool handled)+0x7c字节
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd,int msg,System.IntPtr wParam,System.IntPtr lParam,ref bool handled)+0x14a字节
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(对象o)+0x80字节
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate回调,对象args,int numArgs)+0x5e字节
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象源={System.Windows.Threading.Dispatcher},System.Delegate方法,对象args,int numArgs,System.Delegate catchHandler=null)+0x47字节
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority,System.TimeSpan超时,System.Delegate方法,对象args,int numArgs)+0x2bc字节
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd,int msg,System.IntPtr wParam,System.IntPtr lParam)+0x140字节
[本机到托管转换]
[管理到本机转换]
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame框架)+0x112字节
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window窗口)+0x17a字节
PresentationFramework.dll!System.Windows.Application.Run()+0x67字节
IthacaDbTransferUtil.exe!IthacaDbTransferUtil.App.Main()+0x77字节C#
[本机到托管转换]
[管理到本机转换]
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()+0x5a字节
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(Sys
            var prodRowFindQuery =
                from x in production.AsEnumerable()
                where Convert.ToDateTime(x.Field<MySqlDateTime>("date")) == Convert.ToDateTime(row.Field<MySqlDateTime>("date")) &&
                      x.Field<String>("device_id3") == row.Field<String>("device_id3")
                select x;
            var prodRowFindQuery =
                from x in production.AsEnumerable()
                where x.Field<DateTime>("date") == row.Field<DateTime>("date") &&
                      x.Field<String>("device_id3") == row.Field<String>("device_id3")
                select x;
            var prodRowFindQuery =
                from x in production.AsEnumerable()
                where x.Field<String>("date") == row.Field<String>("date") &&
                      x.Field<String>("device_id3") == row.Field<String>("device_id3")
                select x;
    officialTable = temporaryTable.Clone();
    officialTable.Columns["date"].DataType = typeof(String);