![stdent加名词复数](https://i-blog.csdnimg.cn/blog_migrate/7bd031481520998c8f8c02c4dd0edf81.png)
stdent加名词复数
![Add Entity Pluralization Add Entity Pluralization](https://i-blog.csdnimg.cn/blog_migrate/e5421335067f110f40f31de323ac1268.png)
There was interesting discussion about noun pluralization on a mailing list today. One of the fun demos I throw into some talks is the automatic pluralization (taking something singular and making it plural) that's built into the Entity Framework design time tooling. For example, look at the screenshot to the right where a table of type "Goose" is called "Geese" as a set.
今天,在邮件列表上对名词复数进行了有趣的讨论。 我在演讲中介绍的一个有趣的演示之一是实体框架设计时间工具中内置的自动复数(采用单数形式并将其变为复数形式)。 例如,查看右侧的屏幕快照,其中“ Goose”类型的表被称为“ Geese”。
Dmitry released a nice "Simple English Noun Pluralizer" a few years back. His code is fun to read and clever for under 400 lines.
几年前,德米特里(Dmitry)发布了一个不错的“简单英语名词复音器”。 他的代码很有趣,而且能读不到400行,很聪明。
In addition to Dmitry's, in .NET 4 (Full Framework, not Client Profile) there's a little known PluralizationService inside of System.Data.Entity.Design that supports this user interface.
除了Dmitry的以外,在.NET 4(完整框架,而不是客户端配置文件)中,在System.Data.Entity.Design内部还有一个鲜为人知的PluralizationService支持此用户界面。
At this point there is only support for English and while the class is abstract, there's no proper provider model or factory. Also, personally I think service should be in the Base Class Library (BCL) and should been available as an extension method on string, and I've told them so. That said, it's still pretty cool and useful.
目前,仅支持英语,而该类是抽象的,没有适当的提供程序模型或工厂。 另外,我个人认为服务应该在基类库(BCL)中,并且应该作为字符串的扩展方法使用,我已经告诉过他们。 话虽如此,它仍然非常酷并且有用。
Create a new project in Visual Studio 2010. Right click on the project in the Solution Explorer, and from Properties select ".NET Framework 4" as the Target Framework. Otherwise you won't be able to see System.Data.Entity.Design in the list of .NET Assemblies from the Add Reference dialog. Add a reference, and go to town.
在Visual Studio 2010中创建一个新项目。在解决方案资源管理器中右键单击该项目,然后从“属性”中选择“ .NET Framework 4”作为目标框架。 否则,您将无法从“添加引用”对话框的.NET程序集列表中看到System.Data.Entity.Design。 添加参考,然后去城镇。
Here's some of the things I tried. I was impressed and confused when it changed Hanselman to Hanselmen. ;)
这是我尝试过的一些方法。 当Hanselman换成Hanselmen时,我印象深刻并感到困惑。 ;)
[Test]
public void AnimalsAreFunWhenPluralized()
{
var p = PluralizationService.CreateService(new CultureInfo("en-US"));
Assert.AreEqual("geese", p.Pluralize("goose"));
Assert.AreEqual("deer", p.Pluralize("deer"));
Assert.AreEqual("sheep", p.Pluralize("sheep"));
Assert.AreEqual("wolves", p.Pluralize("wolf"));
Assert.AreEqual("volcanoes", p.Pluralize("volcano"));
Assert.AreEqual("aircraft", p.Pluralize("aircraft"));
Assert.AreEqual("alumnae", p.Pluralize("alumna"));
Assert.AreEqual("alumni", p.Pluralize("alumnus"));
Assert.AreEqual("houses", p.Pluralize("house"));
Assert.AreEqual("fungi", p.Pluralize("fungus"));
Assert.AreEqual("Hanselmen", p.Pluralize("Hanselman"));
Assert.AreEqual("Hanselman", p.Singularize("Hanselmen"));
}
As I mentioned, If you wanted, you could derive from PluralizationService and create a Spanish or whatever-you-like service and plug it into the Entity Framework. Dmitry could even swap out the included service and broker calls to his own.
正如我提到的,如果需要,您可以从PluralizationService派生并创建西班牙文或任何您喜欢的服务,然后将其插入到Entity Framework中。 德米特里甚至可以将包含的服务和经纪人电话换成自己的电话。
Note that this class was really just meant to be used from the EF Tooling, but I'd like to put gentle pressure on the Powers That Be (if this is useful) to put a little more work into it, make it a core thing, and make it work in more languages.
请注意,该类实际上只是打算从EF工具中使用,但是我想对Bes施加强大的压力(如果有用的话),以便在其中进行更多的工作,使其成为核心,并使其支持更多语言。
UPDATED: An interesting point from Jon Galloway. If you are using Entity Framework Code First, you can effectively disable the Pluralization Convention for Table Names by, ahem, removing the PluralizingTableNameConvention. Funny how that works, eh?
更新:乔恩·加洛韦的一个有趣的观点。 如果您使用的是“实体框架代码优先”,则可以通过删除PluralizingTableNameConvention来有效地禁用表名称的复数约定。 有趣的是怎么运作的,是吗?
namespace MvcMusicStore.Models
{
public class MusicStoreEntities : DbContext
{
public DbSet<Album> Albums { get; set; }
public DbSet<Genre> Genres { get; set; }
public DbSet<Artist> Artists { get; set; }
public DbSet<Cart> Carts { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderDetail> OrderDetails { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
}
Cool.
凉。
翻译自: https://www.hanselman.com/blog/fun-with-noun-pluralization-libraries-and-the-net-framework
stdent加名词复数