Poco unsing +调用其他方法来设置业务对象的属性 [英] Poco unsing + Invoke additional method to set property of business object

查看:52
本文介绍了Poco unsing +调用其他方法来设置业务对象的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

 

想象你有一个像以下列一样的表:

imagine you have a table like with the following columns:

ID int - PK

ID int - PK

CompressedInfo NVarChar(Max)

CompressedInfo NVarChar(Max)

 

这一个  ;我想要映射到pocp对象:

This one  i want map to the pocp object:

类MyClass

{

public int ID {get; set;}

public int ID{get; set;}

public string DecompressedValue {get;设置;}

public string DecompressedValue{get; set;}

}

 

问题是否 - 如何自动调用当我选择数据时mehode解压缩()和插入数据时压缩?

The question is no - how can I automatically invoke the mehode Decompress() when i select data and Compress when i insert data?

(concret用例是我有而不是字符串DecompressedValue一个处于压缩xml格式的RuleSet对象DB。我想使用EF,不要使用addidional对象映射,比如DbObject< - > DomainObject)

(The concret use case is that i have  instead of string DecompressedValue an RuleSet object which is in compressed xml format in DB. I want use EF and don't use an addidional object mapping, like DbObject <-> DomainObject)

任何想法?

非常感谢!

 

chris

 

推荐答案

不幸的是,由于EF使用与您相同的属性获取器和设置器,所以选项并不像您所希望的那么好。 解决此问题的最简单方法是创建第二个属性,以便您拥有EF
用于持久性的属性和另一个用于获取值的属性。 你的第二个属性的getter可以从持久化属性中解压缩,它的setter可以压缩回持久化属性。 如果您可以在
fulltrust下运行,那么您甚至可以将持久属性设置为私有,以便对象的使用者无法访问它(EF将生成执行快速反射形式的代码以进行读取/写信给私有财产)。

Unfortunately the options aren't quite as nice as you might like because of the fact that the EF uses the same property getters and setters that you do.  The easiest way to solve this is to create a second property so that you have one which the EF uses for persistence and another one that you use for getting at the value.  Your second property's getter can decompress from the persisted property and its setter can compress back into the persisted property.  If you are OK with running under fulltrust you can even make the persisted property be private so that consumers of your object won't have access to it (the EF will generate code that does a fast form of reflection to read/write to the private property).

- 丹尼


这篇关于Poco unsing +调用其他方法来设置业务对象的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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