Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8807673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:25:33+00:00 2026-06-14T02:25:33+00:00

I’ve managed to stump myself with LINQ. I am trying to create an editable

  • 0

I’ve managed to stump myself with LINQ. I am trying to create an editable datagrid in a WPF app using a subset gathered from a LINQ query:

var LookUpEvents = from d in ThisData.Events.Local
                   where d.StartDate.Value.Date <= DateTime.Now.Date &&
                   (d.EndDate.HasValue == false || d.EndDate.Value.Date >= DateTime.Now.Date)
                   select d;
RangeEventGrid.ItemsSource = LookUpEvents;
RangeEventGrid.Items.Refresh();

This query works, and the datagrid is populated however I am unable to edit the datagrid, when trying to this exception is thrown:

"'EditItem' is not allowed for this view."
   at System.Windows.Controls.ItemCollection.System.ComponentModel.IEditableCollectionView.EditItem(Object item)
   at System.Windows.Controls.DataGrid.EditRowItem(Object rowItem)

When loading the full dataset using:

ThisData.Events.Load();
FullEventGrid.ItemsSource = ThisData.Events.Local;

Everything works fine and the data is editable. The XAML used is identical (I have also tried swapping the bound datagrids and the full result remains editable and the query throws the exception still) and the only difference between these is the query. When I try to change the query I end up with a new exception:

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

The query used for that:

var LookUpEvents = from d in ThisData.Events
                   where d.StartDate.Value.Date <= DateTime.Now.Date &&
                   (d.EndDate.HasValue == false || d.EndDate.Value.Date >= DateTime.Now.Date)
                   select d;
LookUpEvents.Load(); //Exception thrown here.
RangeEventGrid.ItemsSource = LookUpEvents;
RangeEventGrid.Items.Refresh();

The really weird thing about that exception (weird to me at least) is that I use DateTime comparison in other queries that do not throw any exceptions, for example this query in another place works fine:

var LookUpSessions = from d in ThisData.Sessions
                     where d.EndTime.Hour >= (DateTime.Now.Hour - 1) && d.StartTime.Hour <= (DateTime.Now.Hour + 2)
                     && d.Event.IsActive == true
                     orderby d.StartTime.Hour, d.StartTime.Minute
                     select d;

Is it not possible to bind a LINQ query result to a DataGrid to be editable? That seems like it’d be a huge oversight if that’s the case. I feel like it’s much more likely I’m just missing something basic since LINQ, WPF and EF are all brand new to me.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:25:34+00:00Added an answer on June 14, 2026 at 2:25 am

    To make editing data in the GridView possible you cannot use an IEnumerable<T> or IQueryable<T> as the items source. You need a collection type that implemnts IList and IEnumerable<T> or IQueryable<T> don’t.

    A possible solution is that you create an ObservableCollection<T> (that does implement IList) from your LINQ query:

    RangeEventGrid.ItemsSource = new ObservableCollection<Event>(LookUpEvents);
    

    This is also the reason why

    FullEventGrid.ItemsSource = ThisData.Events.Local;
    

    does work because Local is already of type ObservableCollection<Event>.

    Your very first query doesn’t throw an exception (although you are using DateTime.Date) because it is not a LINQ-to-Entities/database query. It is a LINQ-to-Objects query that runs in memory on the Local collection. There is no database query involved.

    If you remove Local you run LINQ-to-Entities and LINQ-to-Entities doesn’t support all methods and properties that LINQ-to-Objects does, especially it doesn’t support DateTime.Date (but apparently is does support DateTime.Hour).

    To perform the comparison by Date in a LINQ-to-Entities query you can use EntityFunctions:

    var today = DateTime.Now.Date;
    var LookUpEvents = from d in ThisData.Events
                       where EntityFunction.TruncateTime(d.StartDate) <= today &&
                             (!d.EndDate.HasValue ||
                              EntityFunction.TruncateTime(d.EndDate) >= today)
                       select d;
    

    Or maybe the EntityFunction.DiffDays function is an option as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.