KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am using Entity Framework 5 - Code first. I have a database that I am connecting to that already exists for some time now (I did not create it). There is a table called T_Customers . It contains a list of all the customers. It has the following structure (only partially shown): Customer_id | numeric (5, 0) | auto increment | not null (not set as primary key) FName | varchar(50) | not null LName | varchar(50) | not null My Customer class: public class Customer : IEntity { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } My IEntity interface: public interface IEntity { int Id { get; set; } } I have the following in my database context class: public class DatabaseContext : DbContext { public DatabaseContext(string connectionString) : base(connectionString) { } public DbSet<Customer> Customers { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new CustomerConfiguration()); } public new DbSet<TEntity> Set<TEntity>() where TEntity : class, IEntity { return base.Set<TEntity>(); } } My customer configuration class: class CustomerConfiguration : EntityTypeConfiguration<Customer> { internal CustomerConfiguration() { this.ToTable("T_Customers"); this.Property(x => x.Id).HasColumnName("Customer_id"); this.Property(x => x.FirstName).HasColumnName("FName"); this.Property(x => x.LastName).HasColumnName("LName"); } } I'm trying to be consistent in my entity declarations, I need all the IDs to be integers. This customer ID is of type num
Tags (comma-separated)
Save Edits
Cancel