[英]How to pass Stored Procedure with DateTime parameter in Entity Framework
public List<Data> GetData(string Date1, string Date2, string param3)
{
var myData= new List<FindData_Result>();
using (var context = new Config())
{
var queryResult = context.FindData(startDate, endDate, param3);
final= (from a in queryResult select a).ToList();
}
}
How do I pass date1 and end date2 as datetime parameter to my stored procedure? 如何将date1和end date2作为datetime参数传递给存储过程?
I am using MVC web api with entity framework (DB first approach) 我正在将MVC Web API与实体框架一起使用(数据库优先方法)
You should convert the string representations of your dates, start date and end date, to their DateTime equivalent. 您应该将日期,开始日期和结束日期的字符串表示形式转换为等效的DateTime。 This can be done by using the Parse
method of DateTime
type, like below: 这可以通过使用DateTime
类型的Parse
方法来完成,如下所示:
var startDate = DateTime.Parse(Date1);
var endDate = DateTime.Parse(Date2);
var queryResult = context.FindData(startDate, endDate, param3).ToList();
You could also use the ParseExact
method, provided that your string have a specific format. 您还可以使用ParseExact
方法,只要您的字符串具有特定格式。 For further info please have a look here . 欲了解更多信息,请在这里看看。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.