Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Time only portion of the date to use in LINQ query
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Titre:
Time only portion of the date to use in LINQ query
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01622912
Message ID:
01622912
Vues:
124
UPDATE. Got some ideas and tests I am working on now.


Hi everybody,

I am trying to figure out a good way to use time only portion of the DateTime value in the LINQ query. The VFP code is the following:
text TO lcSQL TEXTMERGE noshow
        select COUNT(ID) as conflicts
        from dbo.max4sale where <<thisform.cWhere>>
        AND Start_Time >= <<VFP2SQL(m.ltBegin + m.lnStartTime)>>
	    and Start_time <= <<VFP2SQL(m.ltEnd)>>
	    AND CONVERT(varchar(5),Start_Time,108) <= <<VFP2SQL(m.lcEndTime)>>
        AND CONVERT(varchar(5),End_Time,108) >= <<VFP2SQL(m.lcStartTime)>>
        <<m.lcDays>>
		ENDTEXT
and my current code is
  // Set the initial query to find overlapping times. 
            var query = this._siriusContext.Max4Sale.Where(m4s => m4s.StartTime >= beginTime && m4s.StartTime <= endTime 
            && m4s.Id != max4sale.Id && m4s.Type == max4sale.Type);

            if (!String.IsNullOrEmpty(cStartTime))
            {
                
                query = query.Where(m4s=>m4s.StartTime.Value.ToShortTimeString() <= endTime.ToShortDateString() && m4s.EndTime.Value.ToShortTimeString() >= beginTime.ToShortDateString());
            }
which is wrong, obviously. I am wondering if you can suggest what should I use instead.

The other challenge is to also introduce another criterion, e.g.

I have a
List<DayLimit> dayLimits
DayLimit class is the following:
public int MaxSaleLimit { get; set; }
        public string DayName { get; set; }
        public bool Selected { get; set; }
        public short WeekDay { get; set;}
so, my list is populated with

{4, "Monday", selected = true, 1}, {0, "Tuesday", selected= false, 2}, etc. and I will need to add an extra criteria of checking day of the week against the selected days. In VFP that criterion was
' AND DATEDIFF(Day, 0, Start_Time) % 7 IN (' + m.lcDays + ')' 
where lcDays was a string of (0,1,3) etc.

So, these two problems I'm trying to solve starting from the first time portion only.

Thanks in advance for some tips.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform