Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Time only portion of the date to use in LINQ query
Message
 
 
À
05/08/2015 12:08:24
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
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:
01622953
Vues:
217
Strange - I got this error right now:

An exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll but was not handled in user code

Additional information: The specified type member 'TimeOfDay' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

On the line

var Conflicts = query.Count();

----------------------
I tested query (but not count) yesterday in LINQPad and it worked.

Here is my whole code of that method - do you see an error?
public int GetConflicts(Max4Sale max4sale, String cStartTime, String cEndTime, List<DayLimit> dailyLimits)
        {
            DateTime beginDateTime, endDateTime;
            DateTime baseDate = new DateTime(1900,1,1);

          //  System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;

            if (cStartTime == "")
            {
                beginDateTime = max4sale.StartTime.Value;
                endDateTime = max4sale.EndTime.Value;
            }
            else
            {                
                beginDateTime = max4sale.StartTime.Value.Date.AddHours(Convert.ToInt32(cStartTime.Substring(0,2))).AddMinutes(Convert.ToInt32(cStartTime.Substring(3,2)));                
                
                //DateTime.ParseExact(max4sale.StartTime.Value.ToString("MM/dd/yyyy") + " " + cStartTime, "MM/dd/yyyy HH:mm", provider);
                endDateTime = max4sale.EndTime.Value.Date.AddHours(Convert.ToInt32(cEndTime.Substring(0,2))).AddMinutes(Convert.ToInt32(cEndTime.Substring(3,2)));
            }

            // Set the initial query to find overlapping times. 
            var query = this._siriusContext.Max4Sale.Where(m4s => m4s.StartTime >= beginDateTime && m4s.StartTime <= endDateTime
            && m4s.Id != max4sale.Id && m4s.Type == max4sale.Type);

            if (!String.IsNullOrEmpty(cStartTime))
            {
                var startTime = beginDateTime.TimeOfDay;
                var endTime = endDateTime.TimeOfDay;
                var daysOfWeek = dailyLimits.Where(dl => dl.Selected == true).Select(ds => ds.WeekDay).ToList();

                 query = query.Where(m4s => m4s.StartTime.Value.TimeOfDay <= endTime &&
                    m4s.EndTime.Value.TimeOfDay >= startTime);

                if (daysOfWeek.Count() < 7) // not all days of the week selected
                {
                   query = query.Where(m4s=> daysOfWeek.Contains((short)m4s.StartTime.Value.DayOfWeek));
                }
            }

            // Add additional filters based on the type
            switch (max4sale.Type % 10)
            {
                case 1: //DCI
                    query = query.Where(m4s => m4s.Department == max4sale.Department && m4s.Category == max4sale.Category && m4s.Item == max4sale.Item);
                    break;
                case 2:
                    query = query.Where(m4s => m4s.LsnCat == max4sale.LsnCat);
                    break;
                case 3:
                    query = query.Where(m4s => m4s.Lessontype == max4sale.Lessontype);
                    break;
                case 4:
                    query = query.Where(m4s => m4s.LocatnId == max4sale.LocatnId);
                    break;
                case 5:
                    break;
                case 6: // DC
                    query = query.Where(m4s => m4s.Department == max4sale.Department && m4s.Category == max4sale.Category);
                    break;
                case 7: // D
                    query = query.Where(m4s => m4s.Department == max4sale.Department);
                    break;
                case 8: // Sub-Category
                    query = query.Where(m4s => m4s.SubCatId == max4sale.SubCatId);
                    break;
                default:
                    break;
            }

            // Get the count of conflicts
            var conflicts = query.Count();

            return conflicts;
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform