EF架构~在T4模版中自定义属性的getter和setter
T4模版为我们在ORM操作上提供了便捷,它很方便的可以对实体进行全局性的修改,之前我介绍过通过T4来为属性加默认性,而今天我主要告诉大家如何使用T4模版将getter,setter块改为自己需要的,何为自己需要的?这当然是符合你当前项目规则的,如,我希望监听每个属性的修改过程,这正如之前linq to sql的实体类一样,它用来监听你属性的修改前与修改后,在两个时机都可以分别订阅你自己的事件,多么灵活,呵呵。
来看一下,我项目中实体类最后的效果图
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfwAAAGVCAIAAACUy9TWAAAgAElEQVR4nO3d/5MU1b3/8a76/Avkn/D+2rdEEhREAxoSUalriUokt9UoX+IXcBUMJMRVLDMxyCpRBARuTKxA2BttFBTEJIJoNCQSwZFQVxSi6EZUDLFPn9OfH3qmp6e/zPbszkxP93k+aqrY7e3pfvew++rTp2fOMTwAgDaMvAsAAPQOoQ8AGiH0AUAjhD4AaITQBwCNEPoAoJHk0FeqWjENn2WrTu1MnTo0+6FtS4+MssHd9rb/WL39P1Zvj6yZ8ekJ+1XvLX1o1xOnok9M21HCFppej469IADQY61CPxL3QUT+x+rt52w+dKz97EsL36Q1P31iczTfsz89+34Td5S6ndqrQugDKKqsoa9OHZr90P7dvcq7trI4w9YIfQDwvDZDPyEcj+3bFW/+77a3zd7cWO4/K7EvJe3qIZ7F8af76zSeXj8nxbfph/7s+srnhM5e8R0lHlFtZUIfQMG10b2jjuyPxe57S+sBGk7P3fa2c+z3/HV229tm7/u0vn5qszrSGE/p3kl+ujp1aHZSQz7YplLvLa2fsSIbiX2bfES1nxL6AAqujdCv/ejUodkPbau1oE8dmv1Qo1kdbtSnJHssRkOt9XPGFPpZthk5o7Q4D6UdUe2nhD6Agms79L1QUKpTh2Yn3dHNGPrNDfAxtvTDVxVp24yHfmpLP+WIaj8l9AEU3NhCP6HbJCxr6IduDqsj+8fQ0ldH9ke73ZO2GQ79SF9Qi/NQQv2EPoCCy3wjt96h7z8a3SOh5eFbqYl5HV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va5YreJ6nRkbkwYPymWfcRx4RAwPOnDnO5MnOt78t5s93fvxjd9Uqd/Vqd906d8sWd+tWuWOH3LNHvvqqPHhQVavq/ffVJ590KlXVl1+qTz5R77+vqlV58KB89VW5Z4+0bXfrVnfLFnfdOnf1anfVKndwUNxyizNzpjN5sjNnjrjrLvfRR+Uzz8iDB/kwM9CWMoR+u7NcIZH6xz/kgQPujh21wH38cT9wxfLl4s47xYIFwrKcOXOcyy93ZsxwLrhATJzoXHCBM2OGc/nlzpw5wrLEggXizjvFihX+aUM89VRtCytWjG0L7uOP+yced8cO+dpr6sMP836RgMIrQ+jTvZOX1u108atf1a4VbLt71woA2kLoA4BGCH0A0AihDwAaKXzod2mWKwAopWKHfrdnuQKAkil26AMA2kLoA4BGCH0A0AihDwAaIfQBQCOEPgBopHehr+0sVwDQP3ra0td8lisAyF2vu3cYMgEAckToA4BGeh36zHIFADnqdegzyxUA5IjuHQDQCKEPABoh9AFAI4Q+AGiktx/OYpYrAMhVb4dhYAwGAMgVA64BgEYIfQDQCKEPABoh9AFAI4Q+AGiE0AcAjRD6AKARQh8ANPL/AUhRfSRlnhZCAAAAAElFTkSuQmCC" alt="" />
下面是T4模块的属性获取的私有方法代码,源于EF5中的T4模版
public string Property(EdmProperty edmProperty)
{
return string.Format(
CultureInfo.InvariantCulture,
"\r\n{6} {1} {5};\r\n{0} {1} {2} {{ {3}get {{ return {5}; }} {4}set {{ if ({5}!=value) {{ OnPropertyChanging(\"{2}\", {5}) ; {5}=value; OnPropertyChanged(\"{2}\", {5}); }}}} }} ",
Accessibility.ForProperty(edmProperty),
_typeMapper.GetTypeName(edmProperty.TypeUsage),
_code.Escape(edmProperty),
_code.SpaceAfter(Accessibility.ForGetter(edmProperty)),
_code.SpaceAfter(Accessibility.ForSetter(edmProperty)),
"_"+_code.Escape(edmProperty).ToLower(),
"private"
);
}
而最后生成它代码如下
[Serializable]
public partial class WebManageRole_WebManageMenus : Frameworks.Entity.Core.EntityBase
{ private int _webmanagemenus_menuid;
public int WebManageMenus_MenuID { get { return _webmanagemenus_menuid; } set { if (_webmanagemenus_menuid != value) { OnPropertyChanging("WebManageMenus_MenuID", _webmanagemenus_menuid); _webmanagemenus_menuid = value; OnPropertyChanged("WebManageMenus_MenuID", _webmanagemenus_menuid); } } } private int _webmanageroles_manageroleid;
public int WebManageRoles_ManageRoleID { get { return _webmanageroles_manageroleid; } set { if (_webmanageroles_manageroleid != value) { OnPropertyChanging("WebManageRoles_ManageRoleID", _webmanageroles_manageroleid); _webmanageroles_manageroleid = value; OnPropertyChanged("WebManageRoles_ManageRoleID", _webmanageroles_manageroleid); } } }
}
事实上,代码我们并不是很满意,因为它不够漂亮,呵呵,我们更喜欢换行之后的代码,当然你可以在T4里加一个\r\n这种换行标记来实现。
经过我的测试,还是将它换一下行吧,呵呵,格式化一下看着顺眼点,代码如下
public string Property(EdmProperty edmProperty)
{
string strReg=string.Empty;
return string.Format(CultureInfo.InvariantCulture,
@"
{7}{6} {1} {5};
{7}{0} {1} {2}
{{{3}
{8}get
{8}{{
{9}return {5};
{8}}}{4}
{8}set
{8}{{
{9}if ({5}!=value)
{9}{{
{10}OnPropertyChanging(""{2}"", {5}) ;
{10}{5}=value;
{10}OnPropertyChanged(""{2}"", {5});
{9}}}
{8}}}
{7}}} ",
Accessibility.ForProperty(edmProperty),
_typeMapper.GetTypeName(edmProperty.TypeUsage),
_code.Escape(edmProperty),
_code.SpaceAfter(Accessibility.ForGetter(edmProperty)),
_code.SpaceAfter(Accessibility.ForSetter(edmProperty)),
"_"+_code.Escape(edmProperty).ToLower(),
"private",
strReg.PadRight(),
strReg.PadRight(),
strReg.PadRight(),
strReg.PadRight());
}
希望代码可以给你带来快乐!
EF架构~在T4模版中自定义属性的getter和setter的更多相关文章
- EF架构~在T4模版中为所有属性加默认值
回到目录 在项目开发过程中,出现了一个问题,就是新添加一个非空字段后,原来的程序逻辑需要被重新修改,即将原来的字段添加到程序里,这种作法是非常不提倡的,所以,我通过T4模版将原来的实体类小作修改,解决 ...
- T4模版自动生成MSSQL实体类
在Model层建立ModelAuto.ttinclude文件 <#@ assembly name="System.Core"#> <#@ assembly nam ...
- SubSonic3.0 Demo1.0——应用了T4模版可减少开发过程中70%以上的代码量以及80%以上的出错率
应网友的要求,抽了点时间写了这个Demo,希望对2.2版想升级到3.0的朋友或正在使用3.0的朋友有所帮助.大家在使用Demo过程中如果发现什么问题或有什么建议,可以直接将Bug提交给我或告诉我,我会 ...
- EF架构~为EF DbContext生成的实体添加注释(T5模板应用)
回到目录 相关文章系列 第八回 EF架构~将数据库注释添加导入到模型实体类中 第二十一回 EF架构~为EF DbContext生成的实体添加注释(T4模板应用) 第二十二回EF架构~为EF DbCo ...
- EF架构~为EF DbContext生成的实体添加注释(T5模板应用)(转载)
转载地址:http://www.newlifex.com/showtopic-1072.aspx 最近新项目要用Entity Framework 6.x,但是我发现从数据库生成模型时没有生成字段的注释 ...
- EF架构随心所欲打造属于你自己的DbModel【转】
前言 我们都知道EF可以生成Dbmodel,系统生成的Model有时候并不是我们想要的,如何我们要生成自己的Model,那么久需要我们手动的去修改T4模版,T4是对“Text Template Tra ...
- [原创]EF架构随心所欲打造属于你自己的DbModel
前言 我们都知道EF可以生成Dbmodel,系统生成的Model有时候并不是我们想要的,如何我们要生成自己的Model,那么久需要我们手动的去修改T4模版,T4是对“Text Template Tra ...
- 【转】EF架构~为EF DbContext生成的实体添加注释(T5模板应用)
嗨,没法说,EF4的TT模版加上注释后,升级到EF5的TT模版后,注释就不通用了,所以,还得再研究一下,然后把操作方法再分享出来,没辙的微软! T4模版可能有些凌乱,这在T5模版里有了不错的改进,但我 ...
- EF架构~通过EF6的DbCommand拦截器来实现数据库读写分离~终结~配置的优化和事务里读写的统一
回到目录 本讲是通过DbCommand拦截器来实现读写分离的最后一讲,对之前几篇文章做了一个优化,无论是程序可读性还是实用性上都有一个提升,在配置信息这块,去除了字符串方式的拼接,取而代之的是sect ...
随机推荐
- javascript typeof
https://zhidao.baidu.com/question/79159257.html typeof 运算符返回一个用来表示表达式的数据类型的字符串. 可能的字符串有:"number ...
- lua 自己编译源文件
,下载源代码 http://www.lua.org/download.html 直接下载source ,vs2010新建win32项目 应用程序设置中设成静态库 ,将.c(除去lua.c)和.h文件加 ...
- Android Application类作用简单说明
每个程序运行时创建一个Application类的对象且只创建一个 Application对象的生命周期是整个程序中最长的,它的生命周期就等于这个程序的生命周期. Application来进行一些,如: ...
- css study
---恢复内容开始--- html{filter:expression(document.execCommand("BackgroundImageCache",false,true ...
- android手机调试时不能打印Logcat日志信息
方法: 1.在拨号界面输入:*#*#2846579#*#* 进入测试菜单界面 2.Project Menu–后台设置–LOG设置 3.LOG开关–LOG打开 LOG级别设置–VERBOSE 4. ...
- 推荐一款跨平台的 Azure Storage Explorer
var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...
- this、super关键字
this关键字 this 关键字用来表示当前对象本身,或当前类的一个实例,通过 this 可以调用本对象的所有方法和属性. public class Demo{ public int x = 10; ...
- 使用git svn clone迁移svn仓库
使用git svn clone迁移svn仓库 clone命令可以指定很多参数,主要用到这些,你也可以使用git svn help查看完整的参数列表. git svn clone https://172 ...
- Amazon Resource Names (ARNs)
The following are the general formats for ARNs; the specific components and values used depend on th ...
- iOS开发零基础--Swift教程 类型转换
常见的类型转化符号 is : 用于判断一个实例是否是某一种类型 as : 将实例转成某一种类型 例子 // 1.定义数组 let array : [AnyObject] = [12, "wh ...