I'm developing a project in C# / ASP.NET MVC 4 / EF5. The existing database has spaces in the column names, which I've never come across, don't have the authority to change and have no idea how to workaround.
I've tried lots of stuff to get the column name to be read, including below, but can't figure it out. Here is a simplified version of the code with something I tried but didn't work (I'm happy to provide more code if needed):
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'.
BTW, I can successfully connect to all columns that don't have spaces. Thanks for any help!
Thanks to Kirill, here is the answer for people having this problem in the future:
modelBuilder.Entity<TheTable>().Property(p => p.TheColumnName).HasColumnName("The Column Name");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With