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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:01:02+00:00 2026-06-04T20:01:02+00:00

EF Reverse Code First Tool is generating a composite key public vw_ResourcesMap() { //

  • 0

EF Reverse Code First Tool is generating a composite key

public vw_ResourcesMap()
    {
        // Primary Key
        this.HasKey(t => new { t.Refno, t.Obsolete }); // Why???

        // Properties
        this.Property(t => t.Refno)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

        this.Property(t => t.Name)
            .HasMaxLength(50);

        this.Property(t => t.LocnID)
            .IsFixedLength()
            .HasMaxLength(2);

        this.Property(t => t.Created_by)
            .HasMaxLength(50);

        // Table & Column Mappings
        this.ToTable("vw_Resources");
        this.Property(t => t.Refno).HasColumnName("Refno");
        this.Property(t => t.Name).HasColumnName("Name");
        this.Property(t => t.Head).HasColumnName("Head");
        this.Property(t => t.LocnID).HasColumnName("LocnID");
        this.Property(t => t.Obsolete).HasColumnName("Obsolete");
        this.Property(t => t.Created_by).HasColumnName("Created_by");
        this.Property(t => t.Version).HasColumnName("Version");
        this.Property(t => t.Rank).HasColumnName("Rank");
    }
}

I had to change the Primary Key declaration to this.HasKey(t => t.Refno) to map the relationship otherwise I would get the exception below.

The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical.

Maybe it’s a bug — IDK

All is working, but would like to increase understanding and knowledge.

Thanks!

  • 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-04T20:01:04+00:00Added an answer on June 4, 2026 at 8:01 pm

    Database view doesn’t have primary key so EF tries to infer the key by using all non nullable columns which don’t use binary data types.

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

Sidebar

Related Questions

I have found this code for reverse geocoding: var point = new GLatLng (lat[1],long[1]);
This is my code to reverse a string using std::string . But it does
Came across this question: explain the role of dominators in reverse engineering Java code.
Im trying to change this code to do reverse geocoding as well. Coordinates work
After reverse engineering code first, I got entity classes and mapping. Most of the
Take a look at this code: ColorResult contains Index, Color Name, and Probability Colors.Add(new
Given this code: #include <iostream> using namespace std; class Foo { public: Foo ()
I was reverse engineering some code and came across this... /************************************************************************/ /* */ /*
I found this code in Clojure to sieve out first n prime numbers: (defn
Possible Duplicate: Protect .NET code from reverse engineering? we just develop a application with

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.