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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:45:33+00:00 2026-05-17T20:45:33+00:00

I have a POCO class, mapping to a table that basically contain three primary

  • 0

I have a POCO class, mapping to a table that basically contain three primary keys as follow:

public class ContactProjectSite
    {
        public int ContactID { get; set; }
        public int ProjectID { get; set; }
        public int SiteID { get; set; }

        public virtual Contact Contact { get; set; }
        public virtual Project Project { get; set; }
        public virtual Site Site { get; set; }
    }

Here’s the class that inherit the DbContext class, override the OnModelCreating method:

public class TLI : DbContext
{
    public DbSet<ContactProjectSite> ContactsProjectSite { get; set; }
    protected override void OnModelCreating(System.Data.Entity.ModelConfiguration.ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ContactProjectSite>().MapSingleType(cps => new
        {
            cpcid = cps.ContactID,
            cppid = cps.ProjectID,
            cpsid = cps.SiteID
        }).ToTable(new StoreTableName("contacts_ps", "dbo"));
    }
}

However, when running this, I gets this error: *Unable to infer a key for entity type ‘Library.Models.ContactProjectSite’. * Any idea why?

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-05-17T20:45:33+00:00Added an answer on May 17, 2026 at 8:45 pm

    You can apply the [Key] attribute to indicate which property is the primary key when EF can’t figure it out from names/types. I think you can apply it multiple times to create a composite key.

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

Sidebar

Related Questions

I have the following Entity Framework POCO classes: public class Customer { public int
I have the following poco class: public class Category : IDisplayName { private ICollection<Category>
I have a class Something that implements ISomething . How can I convert/cast from
I have an existing POCO class library where children collections are all stored in
I have a script that appends some rows to a table. One of the
Given this table: CREATE TABLE [Comments] ( [Id] [int] IDENTITY(1, 1) NOT NULL, [Text]
Say I've got a domain model created from C# classes like this: public class
I'm trying to work through a problem where I'm mapping EF Entities to POCO
We have a simple Table per Type Entity Framework 4.0 model :- ALl classes
I have a database, and I have entity POCO's, and all I want to

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.