Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6600473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:37:40+00:00 2026-05-25T18:37:40+00:00

I have the following mapping defined: protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<InsuranceProvider>() .Map(ins

  • 0

I have the following mapping defined:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<InsuranceProvider>()
                .Map(ins => ins.Properties(p => new
                {
                    PKID_Insuance = p.Id,
                    InsuranceProvider = p.Name,
                    Address1 = p.Address.Address1,
                    Address2 = p.Address.Address2,
                    City = p.Address.City,
                    State = p.Address.State,
                    Zipcode = p.Address.Zipcode,
                })).ToTable("Insurance");

        }

The table and object both share properties such as Phone and Fax with the same name. Do I need to explicitly map those or will the fall into place magically?

Thanks.

Solution:

Sure enough the mapping I proposed did not work. Once I had it working with the .HasColumnName() method, I swapped that out for the code here and got a “the property expression…. is not valid” error. Bummer.

The scaffold “Create” in MVC 3 did, however, pull both the values I defined in the mapping as well as the ones from the Database with the shared names. Funny how that works.

It would be nice if they brought that syntax back. It seems so much cleaner for remapping large quantities of columns.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:37:40+00:00Added an answer on May 25, 2026 at 6:37 pm

    Did this work at all what you have so far? The usual way to map properties to column names in the DB is:

    modelBuilder.Entity<InsuranceProvider>()
        .Property(i => i.Name)
        .HasColumnName("InsuranceProvider");
    
    modelBuilder.Entity<InsuranceProvider>()
        .Property(i => i.Address.Address1)
        .HasColumnName("Address1");
    // assuming here that Address is a complex property, not a navigation property
    
    // etc.
    

    And then yes, you don’t need to define a mapping for properties which have the same name as the columns in the database. This mapping will happen by convention.

    Alternatively you can use the [Column("...")] attribute on the properties in your model classes (doesn’t work though for complex properties, only for scalars, I think).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following mapping: public class LogEntryMap { public LogEntryMap() { Map.Id(x =>
I have a pre-defined database that I want to map using Entity Framework 4
I have the following class defined in my mapping XML file: <class name=com.data.StateRefData table=STATE_REF>
I have the following mapping: <hibernate-mapping package=server.modules.stats.data> <class name=User table=user> <id name=id> <generator class=native></generator>
I have the following mapping for my table in MySql: <class name=Tag, namespace table=tags
Lets say I have the following mapping: <hibernate-mapping package=mypackage> <class name=User table=user> <id name=id
NHibernate is driving me 'Nuts'!!! I have the following mapping. Which returns this error
I have the following Hibernate Mapping, which has to be mapped using the Table
I have the following iBatis mapping for an Oracle Stored Procedure that returns a
I have a many-to-many mapping defined (only relevant fields included) with FluentNHibernate (v1.0.0.637): //

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.