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 8552947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:32:18+00:00 2026-06-11T14:32:18+00:00

I have a DbModel configuration like so: modelBuilder.Entity<WishlistLine>() .HasKey(w => w.PersistenceKey) .Property(w => w.PersistenceKey)

  • 0

I have a DbModel configuration like so:

modelBuilder.Entity<WishlistLine>()
            .HasKey(w => w.PersistenceKey)
            .Property(w => w.PersistenceKey)
            .HasColumnName("WishlistLineId");

I have a query run via the following two methods:

public IEnumerable<WishlistLine> FetchWishlistLinesUsingLogonName(string logonName)
{
        return GetFromRawSql(@"
    SELECT wl.* FROM WishlistLines wl
    INNER JOIN Accounts a ON wl.AccountId = a.AccountId 
    LEFT JOIN Users u ON u.AccountId = a.AccountId
    WHERE u.LogonName = @p0", logonName);
}

protected IEnumerable<TEntity> GetFromRawSql(string sqlQuery, params object[] parameters)
{
    return _dbSet.SqlQuery(sqlQuery, parameters).ToList();
}

I can “save” WishlistLines into the database through EF without any problems. When I run this query though I get this error:

The data reader is incompatible with the specified 'DataAccessLayer.DatabaseContext.WishlistLine'. A member of the type, 'PersistenceKey', does not have a corresponding column in the data reader with the same name.

I understood that using DbSet<T>.SqlQuery() would map the returned data to the entities but it seems to be ignoring the DbModel configurations. Judging (guessing) from the error message the wrong data reader is being used.

so:

A) am I doing anything wrong?

B) is there a way to make use of EF’s DbModel-aware entity mapper?

  • 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-06-11T14:32:19+00:00Added an answer on June 11, 2026 at 2:32 pm

    Indeed the column name mapping is ignored when you execute a raw SQL query. Here are two references: This pretty dissatisfying thread only for fun, but the following one with a serious answer from the EF team:

    Quote from http://entityframework.codeplex.com/workitem/233:

    The SqlQuery method is designed not to take any mapping into account,
    including mapping that is applied using attributes. It simply matches
    the column names from the results with property names in the object.
    If the column names don’t match you will need to use a column alias
    (AS keyword in SQL Server) to rename the column in the results.

    We agree that it would be useful to have the option to make SqlQuery
    honor Column attributes so we’re keeping this issue open and putting
    it on our backlog for future consideration.

    So, the only workaround seems to be an explicit AS alias instead of a * in your SQL query that specifies your property name as a column alias:

    return GetFromRawSql(@"
        SELECT wl.WishlistLineId AS PersistenceKey,
               wl.SomeOtherColumn AS SomeOtherProperty,
               ...
        ..."
        // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have db model, where one property has auto_now_add=True . But looks like it
I have a model like this: class Users(db.Model): email = db.EmailProperty(required=True, indexed=True) user_name =
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I have a model with a property called tags of type db.ListProperty(db.Key). The app
I have a model which looks like this: class test (db.Model) : tagList =
I have a model which looks like this: class Example (db.Model) : row_num =
I am creating an app on APPHARBOR and I have an entity model for
Let's say I have: class Like(db.Model): user = db.ReferenceProperty(User,collection_name='likes') photo = db.ReferenceProperty(Photo,collection_name='likes_received') created =
I have a question my db model looks like: class UserAnswer (db.Model): user =
I have a db model for which I would like to edit with multiple

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.