WCF数据服务开始保存更改,但不在Silverlight应用程序中保存更改

WCF数据服务开始保存更改,但不在Silverlight应用程序中保存更改,silverlight,entity-framework,wcf-data-services,Silverlight,Entity Framework,Wcf Data Services,要让WCF数据服务在Silverlight中工作,我真是费了好大劲。我正在使用VS2010 RC 我一直在努力解决需要使用web服务器根文件夹中的clientaccesspolicy.xml&crossdomain.xml文件的跨域问题,但我就是无法实现这一点。我已经求助于将Silverlight Web应用程序和WCF数据服务放在同一个项目中来解决这个问题,但是这里的任何建议都是好的 但是现在我可以看到我的数据来自数据库并显示在Silverlight的数据网格中,我认为我的问题已经解决了-但是

要让WCF数据服务在Silverlight中工作,我真是费了好大劲。我正在使用VS2010 RC

我一直在努力解决需要使用web服务器根文件夹中的
clientaccesspolicy.xml
&
crossdomain.xml
文件的跨域问题,但我就是无法实现这一点。我已经求助于将Silverlight Web应用程序和WCF数据服务放在同一个项目中来解决这个问题,但是这里的任何建议都是好的

但是现在我可以看到我的数据来自数据库并显示在Silverlight的数据网格中,我认为我的问题已经解决了-但是没有。我可以编辑数据并且内存中的实体正在更改,但是当我调用
BeginSaveChanges
(使用适当的异步
EndSaveChanges
调用)时,我没有收到任何错误,但数据库中没有数据更新

以下是我的WCF数据服务代码:

public class MyDataService : DataService<MyEntities>
{
    public static void InitializeService(DataServiceConfiguration config)
    {
        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
    }

    protected override void OnStartProcessingRequest(ProcessRequestArgs args)
    {
        base.OnStartProcessingRequest(args);
        HttpContext context = HttpContext.Current;
        HttpCachePolicy c = HttpContext.Current.Response.Cache;
        c.SetCacheability(HttpCacheability.ServerAndPrivate);
        c.SetExpires(HttpContext.Current.Timestamp.AddSeconds(60));
        c.VaryByHeaders["Accept"] = true;
        c.VaryByHeaders["Accept-Charset"] = true;
        c.VaryByHeaders["Accept-Encoding"] = true;
        c.VaryByParams["*"] = true;
    }
}
返回数据的响应字符串绑定到我的网格OK并显示“-1 | False”

我的目的是在这里获得一个概念证明,然后进行适当的关注点分离,将其转化为一个简单的业务线应用程序


我花了好几个小时在这上面。我被逼疯了。有什么办法让它工作吗?

原来我是个白痴。必须在数据上下文上调用
UpdateObject
,以明确声明对象已更新。这太糟糕了。为什么它不能跟踪变化?

原来我是个白痴。必须在数据上下文上调用
UpdateObject
,以明确声明对象已更新。这太糟糕了。为什么它不能跟踪更改?

如果要跟踪更改,需要生成支持它的客户端类,并且需要使用DataServiceCollection来存储结果。这里有一个很好的描述:

如果您想要更改跟踪,您需要生成支持它的客户端类,并且需要使用DataServiceCollection来存储结果。这里有一个很好的描述:

我一直在处理同样的事情,我必须手动执行updateObject,甚至AddLink或SetLInk。这是我不希望写的很多代码。我一直在处理同样的事情,我必须手动执行updateObject,甚至AddLink或SetLInk。这是很多我不希望写的代码。
private MyEntities _wcfDataServicesEntities;
private CollectionViewSource _customersViewSource;
private ObservableCollection<Customer> _customers;

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
    if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
    {
        _wcfDataServicesEntities = new MyEntities(new Uri("http://localhost:7156/MyDataService.svc/"));
        _customersViewSource = this.Resources["customersViewSource"] as CollectionViewSource;
        DataServiceQuery<Customer> query = _wcfDataServicesEntities.Customer;
        query.BeginExecute(result =>
        {
            _customers = new ObservableCollection<Customer>();
            Array.ForEach(query.EndExecute(result).ToArray(), _customers.Add);
            Dispatcher.BeginInvoke(() =>
            {
                _customersViewSource.Source = _customers;
            });
        }, null);
    }
}

private void button1_Click(object sender, RoutedEventArgs e)
{
    _wcfDataServicesEntities.BeginSaveChanges(r =>
    {
        var response = _wcfDataServicesEntities.EndSaveChanges(r);
        string[] results = new[]
        {
            response.BatchStatusCode.ToString(),
            response.IsBatchResponse.ToString()
        };
        _customers[0].FinAssistCompanyName = String.Join("|", results);
    }, null);
}