c# - DbFunctions for DateTime/TimeSpan addition (datetime / time(7) in SQL Server) -


i have following properties in ef6 code-first model:

public datetime starttime { get; set; } public timespan duration { get; set; } 

ef translates sql server columns

starttime datetime duration time(7) 

this works great far.

now want load entries have enddate = startdate + duration after specific datetime value. first, tried this:

db.entries     .where(x => x.starttime + x.duration >= begin)     .tolist(); 

this not work, ef not know how translate datetime + timespan addition operator.

so changed this:

db.entries     .where(x => dbfunctions.addmilliseconds(x.starttime, (int)x.duration.totalmilliseconds)                 >= begin)     .tolist(); 

here, theoretically knows how perform datetime + timespan addition, not know totalmilliseconds function:

system.notsupportedexception: additional information: specified type member 'totalmilliseconds' not supported in linq entities. initializers, entity members, , entity navigation properties supported.

any hints?

instead of saving duration timespane, can save milliseconds component long or int. in case not have convert milliseconds


Comments