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

  • Home
  • SEARCH
  • 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 8342613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:49:25+00:00 2026-06-09T05:49:25+00:00

This is really an EF Code First question, but sometimes the context of OData

  • 0

This is really an EF Code First question, but sometimes the context of OData makes a difference. The question is simple. Our underlying SQL Server tables/views have Identity columns as the (surrogate) primary key. They also have a ‘code’ field which represent unique identifiers which users are familiar with. Simple example: CarModel: Id = 3, Code = ‘Ford’;
I have successfully create the EF Mode and OData to navigate using the ‘Code’ field as the navigation key, using Data Annotations, and the underlying tables/views have indexes on those columns, so this is acceptable. But I would really like to have the Id column as the key, and as the navigation property in the model, but not have it show up in the response. Perhaps this is where the OData part makes a difference, because I would prefer not to do any complex interception and re-shaping of the response. Setting the columns to ‘private’ or even ‘internal’ throws an error during model generation: ‘Table X has no key defined’

Is it possible to define an identity column in the EF Model, but not have it part of the OData entity/response?


Edit:

So, my comment below is still valid. This is both not a good idea for identity/key columns, nor would ‘hiding’ them allow the model to compile correctly. However, thanks to some links from @mreyeros and a social.msdn post from Vitek Karas, here are some notes.
The System.Data.Services namespace has an IgnorePropertiesAttribute. It allows properties in your model to be ‘hidden’. However, as Vitek says, it currently only works with the ReflectionProvider, not with EF. (And you need to make sure you are referencing the correct library if you are using a NuGet managed release.

That said, the fluent configuration API will work in EF/OData:

modelBuilder.Entity<Foo>().Ignore(f => f.Password);

However, not only does it hide a property in the response, it also hides it from the model and the database (which might be okay for read-only query models). So if you mark a navigation key as hidden, the model will not compile. And if you mark any other property as hidden, but reference it in a QueryInterceptor, an exception will be thrown.

  • 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-09T05:49:27+00:00Added an answer on June 9, 2026 at 5:49 am

    I am not 100% sure if this is the case but, if you apply the “ScaffoldColumn(false)” attribute to the property that you want to hide it may work. Here is the MSDN entry for that attribute

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

Sidebar

Related Questions

I've got this really simple piece of code that I thought was the correct
This is probably really stupid but i can't find the problem with my code.
I've tried to really look this one up before asking a question but it
I really don't know where to begin with this question, but the site I'm
it's my first question in this awesome site. I've really searched a lot and
This code returns an error: AttributeError: can't set attribute This is really a pity
This is really confusing me. I will show my code so far. I am
Boy, this one is really weird. I expect the following code to print 1990,
Ok, this one is really weird... I can't show code for it exactly cause
Editing this code here on Stackoverflow and I'm really near to get the result

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.