I'm using c开发者_如何转开发ode-first in entity-framework 4, Entity Framework Feature CTP 3
Is it possible to specify an entity configuration's name? In effect changing the table name from 'xxxSet' to a name of my choice?
Found the documentation. You want to do something like:
public class BloggingModel : ObjectContext
{
public BloggingModel(EntityConnection connection)
: base(connection)
{
DefaultContainerName = "BloggingModel";
}
public IObjectSet<User> Users // ObjectSet name -- you can call it whatever you want
{
get { return base.CreateObjectSet<User>(); }
}
}
class UserConfiguration : EntityConfiguration<User>
{
public UserConfiguration()
{
Property(u => u.Password).HasMaxLength(15).IsRequired();
Relationship(u => u.AuthoredPosts).FromProperty(p => p.Author);
Relationship(u => u.PostedPosts).FromProperty(p => p.Poster);
MapHierarchy(
u => EntityMap.Row(
EntityMap.Column(u.ID, "uid"),
EntityMap.Column(u.Password)
)
).ToTable("Users"); // DB table name -- again, anything you like
}
}
Again, see the linked post for full info.
You can change it from the designer is Visual Studio (the easy way) or from the .edmx file (if you know what you're doing there) as far as I remember. Also try updating to .NET 4.0 and EF4 which was released about 2 months ago so forget about the CTP (there are express versions of Visual C# 2010 or Web Developer 2010 that you can use for free). The designer in this version is more "complete" than the CTP and knows better to name the entities automatically (pluralization).
This is related to EF and not Linq2Sql (which is somehow similar to EF) but I don't know exactly how to change the names there (though there must be a way for sure and one that must be pretty much the same as for EF).
Cheers!
精彩评论