标签: entity-functions

无法使EntityFunctions.TruncateTime()工作

我正在使用Entity Framework Code First.使用LINQ to Entity我想根据DateTime值获取记录.这是我目前的代码:

/// <summary>
/// A method to check and see if the Parsed Game already exists on the
/// database. If Yes, then True is returned, otherwise False is returned.
/// </summary>
/// <param name="context">The Db Context to use</param>
/// <param name="homeTeam">The Name of the Home Team for the Game.</param>
/// <param name="awayTeam">The Name of the Away Team for the Game.</param>        
/// <param name="date">The Date of the Game</param>
/// <returns></returns>
public bool doesGameAlreadyExist(PContext context, String …
Run Code Online (Sandbox Code Playgroud)

linq-to-entities entity-framework-4 c#-4.0 entity-functions

28
推荐指数
2
解决办法
3万
查看次数

EntityFunctions.CreateDateTime问题与linq到实体的闰年

当我的数据库中有闰年时(例如:2012年2月29日).EntityFunctions.CreateDateTime函数抛出System.Data.SqlClient.SqlException: Conversion failed when converting date and/or time from character string.

我的代码在我的asp.net mvc(C#)应用程序中如下:

from u in _entities.tt_Users
let _start_date = u.Start_Date
let _startDate = _start_date.Day
let _startmonth = _start_date.Month
let _startyear = _start_date.Year
let _starthour = u.Start_Time.Value.Hours
let _startminutes = u.Start_Time.Value.Minutes
let _startseconds = u.Start_Time.Value.Seconds
let _startDateWithTime = EntityFunctions.CreateDateTime(_startyear, _startmonth, _startDate, _starthour, _startminutes, _startseconds)
let _startDateWithZeroTime = EntityFunctions.CreateDateTime(_startyear, _startmonth, _startDate, 0, 0, 0)
let _start_datetime = u.Is_Include_Time ? _startDateWithZeroTime : _startDateWithTime
let _end_date = u.End_Date
let _endDate = _end_date.Day …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc linq-to-entities leap-year entity-functions

5
推荐指数
1
解决办法
1452
查看次数