简体   繁体   English

如何在N层架构中通过wcf检测ObservableCollection中已更改的poco实体?

[英]How to detect the changed poco entities in an ObservableCollection over wcf in N-Tier architecture?

I have following layers in my applicaiton Date Layer (reference to Model) Business Layer(reference to Model ,Data) Model Service(WCF)-(reference to Model,Business Layer) UI (WPF/Silver Light) - Connected via WCF service 我的应用程序日期层中有以下几层(对模型的引用)业务层(对模型,数据的引用)模型服务(WCF)-(对模型,业务层的引用)UI(WPF / Silver Light)-通过WCF服务连接

How do i detect the changed poco entities in an ObservableCollection in UI layer? 如何在UI层的ObservableCollection中检测到已更改的poco实体? for sending it back to server from client side for saving ? 从客户端发送回服务器进行保存? instead of sending all data back to sever side(via WCF)? 而不是将所有数据发送回服务器(通过WCF)?

or 要么

how to perform add/delete/update operation on entities in the collection in UI layer? 如何在UI层中的集合中的实体上执行添加/删除/更新操作?

I am using VS2010/2012 C# EF 5 ADO.NET POCOEntityGenerator With WCF Support(for generating .tt templates from Model.edmx) SQL Server 2012 我正在使用带有WCF支持的VS2010 / 2012 C#EF 5 ADO.NET POCOEntityGenerator(用于从Model.edmx生成.tt模板)SQL Server 2012

Even though searched a lot of places I didn't find a proper solution.. please help if any ideas... 即使搜索了很多地方,我也没有找到合适的解决方案..如果有任何想法,请帮助...

Thanks... 谢谢...

The method i followed to create My application is given below link 以下链接给出了我创建我的应用程序所遵循的方法

http://www.toplinestrategies.com/dotneters/net/wcf-entity-framework-and-n-tier-solutions-part-2/?lang=en/comment-page-1/#comment-1954 http://www.toplinestrategies.com/dotneters/net/wcf-entity-framework-and-n-tier-solutions-part-2/?lang=en/comment-page-1/#comment-1954

Only proper solution is to do the change tracking manually. 唯一正确的解决方案是手动进行更改跟踪。 Each POCO object will have IsDirty property and each property of this object will have IsDirty = true in it's setter. 每个POCO对象将具有IsDirty属性,并且此对象的每个属性在其设置方法中将具有IsDirty = true

One way to make it less manual would be to create a framework, that will create wrapper classes, that will do this for you, but this requires large dose of reflection and code-generation. 减少手动性的一种方法是创建一个框架,该框架将创建包装器类,为您做到这一点,但这需要大量的反思和代码生成。 Also, it will still require all properties to be defined as virtual. 同样,它仍然需要将所有属性定义为虚拟。

But generally, you want to refrain from making UI that would require this kind of tracking. 但通常,您要避免制作需要这种跟踪的UI。 When you want to change an entity, load only that entity in Edit window. 要更改实体时,请仅在“编辑”窗口中加载该实体。

POCOs are well-suited for transmitting data between client and server. POCO非常适合在客户端和服务器之间传输数据。 However, if you're looking for objects to actually work with on client and/or server side you may want to consider using self-tracking entities (STE) as these entities contain logic to track their actual changes and status. 但是,如果您正在寻找可在客户端和/或服务器端上实际使用的对象,则可能要考虑使用自我跟踪实体(STE),因为这些实体包含跟踪其实际更改和状态的逻辑。

Yet a better solution is to use the N-Tier Entity Framework which provides functionality to work with EF in n-tier applications. 还有一个更好的解决方案是使用N层实体框架,该框架提供了与EF在n层应用程序中一起使用的功能。 See http://ntieref.codeplex.com/ for more details. 有关更多详细信息,请参见http://ntieref.codeplex.com/

If you are using EF, then your entities have a 'HasChanges' flag you can test against before submitting changes to your context. 如果您使用的是EF,则您的实体具有“ HasChanges”标志,可以在向上下文提交更改之前进行测试。 eg 例如

if (this.CurrentEntity.HasChanges || CurrentEntity.EntityState == EntityState.New)
{
this.SubjectContext.SubmitChanges(Submit_Completed, saveDetails);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM