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

  • Home
  • SEARCH
  • 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 4007420
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:37:49+00:00 2026-05-20T08:37:49+00:00

I am using a book to study, and am stuck here If you have

  • 0

I am using a book to study, and am stuck here

If you have a reference to the bound collection (or can cast the value of the DataGrid’s ItemsSource property to that type), then you should be able to simply call its Add or Insert method.

my xaml page

public About()
        {
            InitializeComponent();

            this.Title = ApplicationStrings.AboutPageTitle;


            EntityQuery<Web.Models.Class1> qry = context.GetProductSummaryListQuery();
            //page 167
            qry = qry.OrderBy(p => p.Name);
            //the following is asynchronous, therefore any immediate WORKING ON RESULT
            //must be done in the oparation.completed event
            LoadOperation<Web.Models.Class1> operation = context.Load(qry);
            dataGrid1.ItemsSource = operation.Entities;



            //context.Class1s.
           // bool changes_there = context.HasChanges;
        }

my class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;


namespace Tutorial1.Web.Models
{
    public partial class Class1
    {

        [Key]
        [Editable(false)]
        public int ID { get; set; }
        public string Name { get; set; }
        public string Number { get; set; }
        public decimal ListPrice { get; set; }
        public byte[] ThumbNailPhoto { get; set; }
        public int? QuantityAvailable { get; set; }
        public string Category { get; set; }
        public string SubCategory { get; set; }
        public string Model { get; set; }
        public bool MakeFlag { get; set; }
    }

}

my service

namespace Tutorial1.Web.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using Tutorial1.Web.Models;

    // TODO: Create methods containing your application logic.
    [EnableClientAccess()]
    public class ProductPMService : DomainService
    {
        private AdventureWorksLTEntities context = new AdventureWorksLTEntities();

        public IQueryable<Web.Models.Class1> GetProductSummaryList()
        {
            return from p in this.context.Products
                   select new Web.Models.Class1()
                   {
                       ID = p.ProductID,
                       ListPrice = p.ListPrice,
                       Name=p.Name
                   };

        }



        public IQueryable<ProductPM> GetProductsFromDB()
        {
            return from p in context.Products
                   select new ProductPM()
                   {
                       ProductID = p.ProductID,
                       Name = p.Name,
                       ProductNumber = p.ProductNumber,
                       ListPrice = p.ListPrice,
                       ModifiedDate = p.ModifiedDate
                   };

        }//get products

        public void InsertProductToDB(ProductPM the_class)
        {
            Product product = new Product();
            product.Name = the_class.Name;
            product.ProductNumber = the_class.ProductNumber;
            product.ListPrice = the_class.ListPrice;
            product.ModifiedDate = DateTime.Now;


            //concurrency
            //ProductPM originalproduct = ChangeSet.GetOriginal<ProductPM>(the_class);


            context.Products.AddObject(product);
            context.SaveChanges();

            ChangeSet.Associate(the_class, product, UpdateProductPMKeys);
        }//InsertProduct

        private void UpdateProductPMKeys(ProductPM the_class, Product product)
        {//reflecting the generated id back.
            the_class.ProductID = product.ProductID;
            the_class.ModifiedDate = product.ModifiedDate;
        }//reflecting the generated id back ends


        protected override void OnError(DomainServiceErrorInfo errorInfo)
        {
            // Log exception here
                    }

    }
}

I don’t understand what is the binding source, and where I am supposed to add a row when on button click.

  • 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-05-20T08:37:50+00:00Added an answer on May 20, 2026 at 8:37 am

    I see two issues in your code.

    1) In the code behind of your xaml page you assign the results of the load operation to your datagrid’s ItemsSource.

    dataGrid1.ItemsSource = operation.Entities;
    

    The problem with that is that operation.Entities is of Type IEnumerable<TEntity> and therefore does not have an Add-method. I suggest defining an ObservableCollection and using that as the ItemsSource and filling it with the contents of operation.Entities in the callback method of your Load-operation.
    Perhaps you could use something like this (simplified version, not tested):

    public ObservableCollection<Web.Models.Class1> Class1Collection { get; set; }
    
    context.Load<T>(qry, r =>
    {
      if (r.HasError)
      {
        // error handling
      }
      else if (r.Entities.Count() > 0)
      {
        this.Class1Collection.Clear();
        foreach (Web.Models.Class1 c in r.Entities)
        {
          this.Class1Collection.Add(c);
        }
      }
      else 
      {
        // handle case when no Entities were returned
      }
    }, null);
    

    In your constructor use this:

    dataGrid1.ItemsSource = this.Class1Collection;
    

    If you do this, you can add a new Item by using:

    Web.Models.Class1 newItem = new Web.Models.Class1();
    this.Class1Collection.Add(newItem);
    context.GetEntitySet<Web.ModelsClass1>().Add(newItem);
    

    2) You did not define an Insert or Update method for Class1 in your DomainService.
    I am a little confused by your use of Class1 and ProductPM. Are they supposed to be the same?

    Anyway, if you want to add new instances of Class1 you need to have an InsertClass1(Class1 newObject) method in your DomainService (and preferably an Update method, too).

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

Sidebar

Related Questions

I have two tables, Book and Tag , and books are tagged using the
My Book app gathers a collection of Book objects using lookups against different Merchant
After reading the Head First Design Patterns book and using a number of other
Am building a Book search API using Lucene. I need to index Book Name,Author,
Almost every Java book I read talks about using the interface as a way
The Dragon Book includes an exercise on converting integers to roman numerals using a
I'm trying to learn Scheme from the book The Little Schemer using DrScheme on
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
I have this method in my book model: def get_absolute_url(self): return /book/%s/%s/%i/%i/ % (

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.