Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 4: Any way to know the plural form of an Entity Type?

Given this code:

private ObjectQuery<E> GetEntity()
{   // Pluralization concern.  Table and Type need to be consistently named.
    // TODO: Don't get cute with database table names.  XXX and XXXs for pluralization
    return _dc.CreateQuery<E>("[" + typeof(E).Name + "s]");
}

Is there any way to determine an Entity type's plural name so I can access the table, rather than just adding an 's' to the name?

For example, Medium is singular and Media is plural.

like image 481
Zachary Scott Avatar asked Jan 30 '26 06:01

Zachary Scott


1 Answers

You can also use the PluralizationService provided by EF 4. Here is a blog post that covers the service in good detail.

http://web.archive.org/web/20130521044050/http://www.danrigsby.com/blog/index.php/2009/05/19/entity-framework-40-pluralization

like image 110
Chris Taylor Avatar answered Jan 31 '26 20:01

Chris Taylor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!