Entity Framework: naming conventions / sentences for EDMX file and entity class?

I have not had much contact with the Entity Framework yet, and so I would like to hear some guys with experience.

I have an MVC project and my DataAccess is in another project where I want to host my EDMX file.

So, what would I like to name this file? By default, this is "Model1.edmx", but in the MVC context, I do not like this name. Is this really a model? I usually call it “DbModel” or something to indicate that this is database related stuff.

And what do you guys call an entity class? It seems to me that I like the typical EF name "DbContext".

So, inside my controllers, I have something like

public class WorldController : Controller { DbContext db = new DbContext(); public ActionResult Own() { var allContinents = db.Continents; [...] } } 

Sorry for the fussiness, but I really care about the name.

+7
source share
2 answers

Take good care of the name!

How to do this depends on the composition of your application. Let's say you have a web application for registering UFO sightings, to name something in common. If there is a separate part of your db (maybe a separate scheme) containing users, roles and permissions, you can create a context called AuthorizationContext, and for a business part, a context called UfoDbContext.

I mean, if there are explicit aggregates without any overlap, you can create separate contexts for them with clear names. If any context matches the bill, I would still give it some meaningful name (and not DbContext) related to your application domain.

There are people (I'm not one of them) who like to work with one context for each application, a “column” (from db to UI) or “user history”. Significant names are even more important then.

+7
source

My suggestion would be to use something that points to the contents in the naming convention. For example, you could take part in the name of your project and transfer it to the name EDMX. Include something that makes it less common.

I also tend to include "Ef" in my name, which I started when working on a project that already had an existing ORM.

To take Microsoft's prototype example: if your project came under the umbrella name Norwind, here is what I would name some of the files in my model project:

EDMX File: NorwindEfModel.edmx

Generator / TT file: NorwindEfDbContext.tt

Entity Class: NorwindEntities

I can’t say that this is exactly how Microsoft would have it if you downloaded a sample project from them (although I think it will be similar), but I believe that this is a reasonable naming structure and it fits my needs. The bottom line is that it pretty much comes down to the opinion and your need for a specific difference.

+3
source

All Articles