使用$ C C首先$和复数ONLY`DbSet&LT;实体&GT; Entities`项 [英] Using Code First and pluralizing ONLY `DbSet<Entity> Entities` entries
本文介绍了使用$ C C首先$和复数ONLY`DbSet&LT;实体&GT; Entities`项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想禁用多元化的数据库表是很容易的。不过,我使用反射和T4模板来生成我的上下文类。
I want to disable pluralization for database tables which is easy enough. However, I use reflection and T4 templates to generate my context class.
public DbSet<User> User { get; set; }
public DbSet<Department> Department { get; set; }
有没有办法使用EF的从T4模板内返回多元化的名字,所以我可以生成以下内容:
Is there any way to use EF's to return pluralized names from within T4 templates so I can generate the following:
public DbSet<User> Users { get; set; }
public DbSet<Department> Departments { get; set; }
喜欢字符串名称有些功能= EF.GetPluralizedName(用户);
等
我使用VS2010针对.NET 4的情况下,帮助。
I am using VS2010 targeting .NET 4 in case that helps.
推荐答案
您可以使用多元化服务,它会是这样
you can use pluralization service it would be something like
string name = System.Data.Entity.Design.PluralizationServices.PluralizationService.
CreateService(System.Globalization.CultureInfo.CurrentUICulture).Pluralize("User");
这篇关于使用$ C C首先$和复数ONLY`DbSet&LT;实体&GT; Entities`项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文