I have the Client class defined. I also have Mapping\ClientMap.cs file that defines column names using Fluent API. However, I am not sure how to “invoke” it as I don’t see the ClientMap.cs code being executed.
I also have this:
namespace CardNumbers.Data
{
public class Repository : DbContext, IRepository
{
public DbSet<Client> Clients { get; set; }
public DbSet<ClientOrder> ClientOrders { get; set; }
public DbSet<Reorder> Reorders { get; set; }
public DbSet<Operator> Operators { get; set; }
which I know is not a very good practice, but that’s how we were building the application with the instructor.
So, my question is – what do I need to add to make sure the Fluent API code is invoked in run-time?
Thanks in advance.
The fluent mapping should be added at the bottom of your “
Repository” class like thisThe reason I am quoting your Repository is that you are not really implementing a repository pattern there. You should really have this defined as a specific DbContext, and then have a repository which can take multiple contexts. See this very well written post about implementing a repository: http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application