DbFunctions.AddMinute如何在lambda表达式中使用? [英] DbFunctions.AddMinute How to use in lambda expression?
问题描述
您好
我需要删除db中的所有项目,并将特定字段中的日期设为30分钟。
I need to delete all items in db with have the date in a specific field previus 30 minutes.
I用这个 :
I use this :
hT.Delete(t => t.TRA_INPDAT< DbFunctions.AddMinutes(DateTime.Now,-30).Value);
hT.Delete(t => t.TRA_INPDAT < DbFunctions.AddMinutes(DateTime.Now,-30).Value);
但是不要工作..我从来没有使用过Dbfunction而且不会因为不工作而不足。
But don't work.. I never used Dbfunction and don't underdand because don't work.
你可以帮帮我吗?
BR
推荐答案
尝试在发出查询之前声明DateTime对象,例如(TRA_INPDAT是实体类的DateTime属性):
Try to declare the DateTime object before you issue the query, e.g. (TRA_INPDAT is a DateTime property of your entity class):
DateTime date = DateTime.Now.AddMinutes(-30);
context.hT.Delete(t => t.TRA_INPDAT.Equals(date));
希望有所帮助。
请记住通过将有用的帖子标记为答案来关闭您的主题,然后如果您有新问题则启动新主题。请不要在同一个帖子中提出几个问题。
Hope that helps.
Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.
这篇关于DbFunctions.AddMinute如何在lambda表达式中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!