STE问题删除记录 [英] STE problem deleteing records

查看:78
本文介绍了STE问题删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Silverlight应用程序,我使用Beta2  T4 Self跟踪实体。插入和更新记录似乎正在起作用,但我无法删除项目。

我的主要实体叫合同。它具有 Contract2Service集合的导航属性实体。
当我检索一个Contract对象时,我可以这样做:

Contract2Service rem = myContract。 Contract2Service.First();
myContract。 Contract2Service.Add(new Contract2Service(){ServiceID =  5});
myContract。 Contract2Service.Remove(rem);
当我在我的WCF服务中应用更改时,我将添加新的Contract2Service但是我要删除的那个不会被删除。


这是如何保存在WCF中:

使用(var ctx = new AspenNet_VContractEntities())
{
ctx.Contracts.ApplyChanges(contract);
返回ctx.SaveChanges()> 0;
}


任何可能导致此问题的想法?

解决方案

早上好!


我遇到同样的问题。我正在使用Visual Studio 2010 RC(ST​​E-Template的新版本)。我的项目不是Silverlight应用程序,但问题是一样的。


我有一个简单的模型,在人和订单之间有一个1 ... n的关系,一个... ... n订单和地址之间的关系。喜欢这样:


+++++++++++++++++++++               ;       +++++++++++                 +++++++++++++++     人     +    1 ......... n  +       订购      +   1 ......  N'NBSP; +   地址    +
+++++++++++                     +++++++++++                 ++++++++++++++++++++++++++++++++++++++++++++当我现在添加或修改其中一个实体时,一切正常。但是当我从DataGridView /从集合中删除一个地址时,订单对象的ObjectChangeTracker会通知一个地址已被删除。添加了ChangeTracker中的objectsRemovedFromCollections集合的entery。但是它自己的地址没有标记为已删除且仍处于未更改状态。


在我存储更改之前,我调用 context.person.ApplyChanges< person(_person)适用于修改或添加实体但不能删除!


上周我遇到了与"旧"相同的问题。自我跟踪 - 实体模板(CTP2的一部分)和VS 2010 Beta2。我修改了模板,并在第780行(模板调整评论之间)添加了以下内容:


 

 if (e.OldItems!= NULL)
{
的foreach(小于#= code.Escape(navProperty.ToEndMember.GetEntityType())#>在项e.OldItems)
$ { b $ b将(!逆= NULL)#
如果
{
如果(inverse.ToEndMember.RelationshipMultiplicity = RelationshipMultiplicity.Many!)
{
#> ;
if(ReferenceEquals(item。<#= code.Escape(inverse)#> ;, this))
{
item。<#= code.Escape(inverse)#> ; = null;

// BEGIN TEMPLATE适应
如果(产品IObjectWithChangeTracker&安培;&安培; item.ChangeTracker.ChangeTrackingEnabled)
{
item.MarkAsDeleted();
}
// END模板适应
}
<#
}
其他
{
#>

通过此修改,地址被标记为已删除,并且工作正常。但我对此并不满意,在新模板中它看起来总是不同。
这是一个错误还是我错过了什么?


 


感谢您的帮助!


BR Florian G。


 


<编辑:
我的解决方法现在也在使用新模板。我将此代码添加到模板中(在项目之后。<#= code.Escape(反向)#> = null; 在第964行中):



 if(item is IObjectWithChangeTracker&& item.ChangeTracker.ChangeTrackingEnabled)
{
item.MarkAsDeleted();
}


但我仍然不能相信这可以作为解决方案......


I have a Silverlight application that I use the Beta2 T4 Self tracking entities for. Inserting and updating records seems to be working but I haven't been able to remove items.

My primary entity is called Contract. It has a navigation property to a collection of Contract2Service entities.
When I retrieve a Contract object I can do this:

Contract2Service rem = myContract.Contract2Service.First();
myContract.Contract2Service.Add( new Contract2Service() { ServiceID= 5 });
myContract.Contract2Service.Remove(rem);

And when I apply the changes in my WCF service I'll get the new Contract2Service added but the one I want to remove is not deleted.


Here's how the save is in WCF:

using (var ctx = new AspenNet_VContractEntities())
{
                ctx.Contracts.ApplyChanges(contract);
                return ctx.SaveChanges() > 0; 
}

Any ideas what might cause this?

解决方案

Good Morning!

I have the same problem. I'm using the Visual Studio 2010 RC (new version of the STE-Template). My project isn't a Silverlight application but the problem is the same.

I have a simple model with a 1...n relationship between person and order and a 1...n relationship between order and address. Like this:

+++++++++++                    +++++++++++                 ++++++++++
+       person      +    1 ......... n  +        order       +   1 ......  n  +     address    +
+++++++++++                    +++++++++++                 ++++++++++

The data were presented in a WF-GUI with some textboxes for the properties of the person and two DataGridViews for the order and address. When I now add or modify one of the entities everything works fine. But when I delete a address from the DataGridView / from the collection it the ObjectChangeTracker of the order object notify that an address has been deleted. An entery to the objectsRemovedFromCollections collection in the ChangeTracker is added. But the address it self is not marked as deleted and still in the unchanged state.

Before I store the changes I call context.person.ApplyChanges<person(_person) which works fine for modifieing or adding entities but not for deleting!

Last week I had the same problem with the "old" Self-Tracking-Entity Template (part of the CTP2) and VS 2010 Beta2. I modified the template and added the following at line 780 (between the Template Adaption comments):

 

        if (e.OldItems != null)
        {
            foreach (<#=code.Escape(navProperty.ToEndMember.GetEntityType())#> item in e.OldItems)
            {
<#
                if (inverse != null)
                {
                    if (inverse.ToEndMember.RelationshipMultiplicity != RelationshipMultiplicity.Many)
                    {
#>
                if (ReferenceEquals(item.<#=code.Escape(inverse)#>, this))
                {
                    item.<#=code.Escape(inverse)#> = null;

		// BEGIN TEMPLATE ADAPTION
		if (item is IObjectWithChangeTracker && item.ChangeTracker.ChangeTrackingEnabled)
		{
			item.MarkAsDeleted();
		}
		// END TEMPLATE ADAPTION
                }
<#
                    }
                    else
                    {
#>

With this modification the address was marked as deleted and it worked fine. But I'm not really happy with that and in the new template it looks different anyway.
Is that a bug or I'm missing something?

 

Thank's for your help!

BR Florian G.

 

Edit:
My workaround is now also working with the new templates. I added this code to the template (after item.<#=code.Escape(inverse)#> = null; in line 964):

if (item is IObjectWithChangeTracker && item.ChangeTracker.ChangeTrackingEnabled)
{
	item.MarkAsDeleted();
}

But I can still not belive that this can be the solution...


这篇关于STE问题删除记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆