Given an EntityType, such as \"Contact\", how can I derive from it the name of the EntitySet it would belong to, i.e. the pluralization such as \"Contacts\"?
This extension may be useful
public static class MyExtensions
{
public static string GetEntitySetName(this ObjectContext context)
{
string className = typeof(T).Name;
var container = context.MetadataWorkspace.GetEntityContainer(context.DefaultContainerName, DataSpace.CSpace);
string entitySetName = (from meta in container.BaseEntitySets
where meta.ElementType.Name == className
select meta.Name).First();
return entitySetName;
}
}
And use it like:
db.AttachTo(db.GetEntitySetName(), myEntityInstance);