文本转换&寻找实体(收藏) [英] Text Transformations & Finding Entity Plural (Collection)

查看:134
本文介绍了文本转换&寻找实体(收藏)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个.tt模板,我可以使用entity.Name来写出一个实体的名称,例如:

If I have a .tt template, I can use entity.Name to write out the name of an entity, e.g:

foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{;
    WriteLine(entity.Name); 
}

使用正常的转换或T4,如何写出实际实体集的名称? (例如,对于人而言,可能是人 - 但也许我将其改为设计师中的人,所以我想要这样)。

Using normal transformations or T4, How do I write out the actual name of the entity set? (E.g. for Person, it might be Persons - but maybe I changed it to People in the designer, so I'd want that instead).

谢谢!

Richard

推荐答案

我正在寻找同样的问题的答案,发现这不算太糟糕但是,您不需要获取EntitySet名称,而是使用相同的多元化器来实现。

I was looking for the answer to the same question and found that it's not too bad. However, instead of getting the EntitySet name, it's quite easy to use the same pluralizer.

在您的文本模板中,大概在顶部,添加以下行: p>

In your text template, presumably at the top, add the following lines:

<#@ assembly name="System.Data.Entity.Design" #>
<#@import namespace="System.Data.Entity.Design.PluralizationServices" #>

这样可以创建一个多元化器实例:

This allows you to create a pluralizer instance as such:

<# PluralizationService pluralizer = PluralizationService.CreateService(System.Globalization.CultureInfo.CurrentCulture); #>

然后在模板中复合一个实体,只需使用:

Then to pluralize an entity in the template, just use this:

<#=pluralizer.Pluralize(code.Escape(entity))#>

当然,您可以替换 code.Escape(entity)存储实体名称的变量的名称。

Of course, you can replace code.Escape(entity) with the name of your variable storing the entity name.

就是这样!



在t4模板中可以导入哪些库有什么限制吗?
http://vthornheart.railsplayground.net/blog/archives/655

这篇关于文本转换&amp;寻找实体(收藏)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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