0

With version 4 of the Entity Framework, you have the option to doing what they call Code First. The thing is that the naming of your classes and fields/properties need to match the database from what I know. I am using MySQL and as such I use all lowercase and underscores in naming as capitalization is not supported on all OSes and can make MySQL act weird if you try to force it. The issue is that I use the standard C# naming conventions of using camelCase and PascalCase. Is there a way to map the naming in my database to my classes in C# without using the entity model designer (the .edmx file) as the design seems a bit buggy. Thanks.

1 Answer 1

2

You can use the overridable method OnModelCreating which will run on first instantiation of the class. There you can override individual tables like so

public class Context : DbContext {

    //your models

    protected override void OnModelCreating(ModelBuilder modelBuilder) {
        modelBuilder.Entity<SomeTable>()
                         .MapSingleType()
                         .ToTable("YourTableNameInDatabase");
    }
}

It's that simple :)

Sign up to request clarification or add additional context in comments.

2 Comments

The model classes does extend or anything so there are no override-able methods since it is just a POCO.
You're correct, however the DbContext class is the class with the override.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.