Model MVC 4 - EF with space

I am developing a project in C # / ASP.NET MVC 4 / EF5. There are gaps in the existing database in column names that I have never met, do not have the authority to change, and have no idea how to work around.

I tried a lot of things to read the column name, including below, but can't figure it out. Here is a simplified version of the code with something that I tried but didn't work (I'm glad to provide more code if necessary):

using System; using System.ComponentModel.DataAnnotations; using System.Web.Mvc; using System.Data.Linq.Mapping; namespace Domain.Entities { public class TheTable { public int id { get; set; } [Column(Name="The Column Name")] public int TheColumnName { get; set; } } } 

I always get this as a result:

Invalid column name 'TheColumnName'.

By the way, I can successfully connect to all columns that have no spaces. Thanks for any help!

+4
source share
1 answer

Thanks Cyril, here is the answer for people having this problem in the future:

 modelBuilder.Entity<TheTable>().Property(p => p.TheColumnName).HasColumnName("The Column Name"); 
+3
source