views:

46

answers:

1

I have a rather large table of mineral/vitamin definitions (44 columns) and every column name but one is correct. I have a column called [Tryptophan/60] in the SQL database table and I need to represent this in my EF DTO Object MineralDefinition:

public class MineralDefinition
{
    public int DefinitionId {get;set;}
    public string Tryptophan60 {get;set;}
    // 43 other minerals/vitamins
}

Unfortunately I cannot change the columns in the database. Is there any way I can remap this single column without having to write out every column? And, come to think of it, how do I remap the field anyway as it has a / in it?

+2  A: 

Update

It looks like it isn't possible to map only one column and is a feature that would need to be requested to get into the next EF.

This should get you on the right direction. You'll need to using System.Data.Entity.ModelConfiguration for the EntityMap

protected override void OnModelCreating(ModelBuilder modelBuilder) {
    modelBuilder.Entity<Test>().MapSingleType(m => EntityMap.Row(
        EntityMap.Column(m.Tryptophan60, "Tryptophan/60")
    )).ToTable("MineralDefinition");
}

You might have to add modelBuilder.IncludeMetadataInDatabase = false; in order to avoid model change errors.

BuildStarted
Thanks, but that still requires listing every single column. Is there no way to do it without listing all 44 columns?
GenericTypeTea
I just finished talking with Jon Galloway about this issue and the basics of the conversation is that it's a feature (single column mapping) that should definitely be requested but is currently unavailable.
BuildStarted
http://data.uservoice.com/forums/72025-ado-net-entity-framework-ef-feature-suggestions You can vote for feature additions for Entity Framework here
BuildStarted