通过 LINQ 插入日期时间
我的表中有一个数据类型为“时间戳”的列。现在我通过 LINQ2SQL 插入一行。现在我应该在这里写什么:
Entity_Product_Point ev = new Entity_Product_Point();
ev.DateCreated = ???
谢谢!
I have a column in my table which has a DataType of 'timestamp'. Now I am inserting a row through LINQ2SQL. Now what should I write here:
Entity_Product_Point ev = new Entity_Product_Point();
ev.DateCreated = ???
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定要 时间戳?它与日期无关...如果您想存储“DateCreated”,我想您可能想使用
DateTime
或只是Date
数据类型MSSQL。如果这就是您真正想要的,那么您可以传入DateTime.Now
作为值。Are you SURE you wanted timestamp? It has nothing to do with dates... If you'd like to store "DateCreated", I think you probably want to use either a
DateTime
or justDate
datatype in MSSQL. If that's what you really intended, then you can pass inDateTime.Now
for a value.相应的类型是 byte[],但 SQL Server 在内部使用此类型进行行版本控制,并由 ORM 进行乐观锁定。您永远不应该(不能)手动为时间戳列写出值。
有关哪种类型对应什么的更完整列表,请查看此问题
Well the corresponding type would be
byte[]
, but this type is used internally by SQL Server for row versioning—and by ORMs for optimistic locking. You should never (can't) write a value out for a timestamp column manually.For a more complete listing of which type correspond to what, check out this question