Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ to SQL: there was an error in a part of the date format
    primarykey
    data
    text
    <p>I have an application where I want to find the distinct available months that are available in a given year. However, with the query below I get the error message </p> <blockquote> <p>There was an error in a part of the date format. [ Expression (if known) = ]</p> </blockquote> <p>when I try to execute the following query:</p> <pre><code>IQueryable&lt;DateTime&gt; availableMonths = (from item in database.IntakeItems where item.Timestamp &gt;= statsYearStart &amp;&amp; item.Timestamp &lt;= statsYearEnd select new DateTime(1, item.Timestamp.Month, 1)) .Distinct() .OrderByDescending(y =&gt; y.Month); </code></pre> <p>The <code>statsYearStart</code> and <code>statsYearEnd</code> are created in a property-setter and contain valid DateTime when the query is executed:</p> <pre><code>statsYearEnd = new DateTime(value, 12, 31); statsYearStart = new DateTime(value, 1, 1); </code></pre> <p>The database is created via a code-first approach using EntityFramework. The column for item.Timestamp is defined as:</p> <pre><code>private DateTime timestamp; [Column] public DateTime Timestamp { get { return timestamp; } set { if (timestamp != value) { NotifyPropertyChanging(); timestamp = value; NotifyPropertyChanged(); } } } </code></pre> <p>I'm pretty new to LINQ and EF, so let me know if you need additional information. At first I suspected that this could be because of a localization issue (the Application), however I'm not using <code>.ToString</code> on any of the <code>DateTime</code>s. What might cause the exception?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload