views:

177

answers:

2

Hi,

I'm using code-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?

A: 

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!

Padel
Please read my post again. I added additional info. I'm not using a designer, code-first only using the Entity Framework Feature CTP3.
Jeroen
Sorry about the misunderstanding... My bad here! I haven't used code first with EF yet (only DB first) so I don't know the answer on this one...
Padel
+1  A: 

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.

Craig Stuntz
Yea i have seen this before. But the thing is i don't use MapHierarchy. On to the documentation. Thanks
Jeroen