Given date range in Table for particular record say for particular feild “Name”
If some one trying to insert that Name within previous date range interval then it should not be allowed.
I have tried here some code look at this …
if (dataContext.TableAs.Where(
x => x.EndDate > StartDate &&
x.Name == Name).Count() == 0)
{
//insert record
}
but is not successful all times.
Can anyone suggest what I have missing over here ?
I have tried below query in SQL , how can I use that in LINQ for above code
SELECT COUNT(*) FROM TableA WHERE ('2012-04-02' between StartDate and EndDate or '2012-08-28'
between StartDate and EndDate or StartDate between '2012-04-02' and '2012-08-28' or EndDatebetween '2012-04-02' and '2012-08-28' ) and Name='Test'
try this;
EDIT – For second part of question