English 中文(简体)
LINQ 设定日期,但不是时间
原标题:LINQ to SQL sets date but not time...sometimes

麻烦。 我有3个地方/区,在那里这样做。

var o = db.Orders.Where(a => a.OrderID == orderID).First();
o.dateOne = DateTime.Now;
db.SubmitChanges();

如今,所有东西都是好的......在2011-04-01年,12:12:33

At two other places I do the same for...

o.dateTwo = DateTime.Now;
o.dateThree = DateTime.Now;
db.SubmitChanges();

这两个物体的日期是正确的,但在亚洲开发银行,它称2011-04-0100:00:00

我曾试图在SubmitChanges之前展示该物体的价值。 此时此刻的价值与时俱进,例如2011-04-0112:12:33

Other info: DB is MS sql, all columns are date/time, .NET 3.5...

是否有任何人经历过同样的行为?

最佳回答

您能否抓住正在用SQLQ简介仪向服务器发送的KQQ号声明? 然后,你能够告诉发生拖拉的情况。

exec sp_executesql 
UPDATE [MyTable]  SET [dateTwo] = @p0
WHERE ... ,
...--and then defining the value of your datetime
@p0 =  2011-04-01 00:00:00 
问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

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. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签