【发布时间】:2011-02-22 08:40:14
【问题描述】:
我正在用书学习,卡在这里
如果您有对绑定集合的引用(或者可以将 DataGrid 的 ItemsSource 属性的值转换为该类型),那么您应该能够简单地调用其 Add 或 Insert 方法。
我的 xaml 页面
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;
}
我的班级
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; }
}
}
我的服务
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
}
}
}
我不明白什么是绑定源,以及在单击按钮时我应该在哪里添加一行。
【问题讨论】:
标签: silverlight datagrid