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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:48:36+00:00 2026-06-16T08:48:36+00:00

I have class hierarchy like following: class BaseType { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int Id

  • 0

I have class hierarchy like following:

class BaseType
{
  [Key]
  [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
  public int Id { get; set; }

  [DataType(DataType.Text)]
  [StringLength(100)]
  public string CreatedBy { get; set; }

  [DataType(DataType.DateTime)]
  public DateTime? CreatedDate { get; set; }
....
}

class Group : BaseType
{
  public string Name { get; set; }
}

Here is OnModelCreating method of context:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<MCQGroup>()
        .HasKey(t0 => t0.Id)
        .Map(m => m.ToTable("groups"))
        .HasMany(t1 => t1.Sections)
        .WithMany(t2 => t2.Groups)
        .Map(m =>
          m.MapLeftKey("group_id")
          .MapRightKey("section_id")
          .ToTable("groups_to_sections"));
  ...........
  }

I am not using automatic table generations or migrations. Instead I have number of scripts to create database (actually, I used autogeneration for the first run and after that script created tables include webdata_* tables). This caused by multiple contexts used and in this case there are number of issues with table autogeneration.

Here is SQL scripts:

-- Tables creation

CREATE TABLE [groups]
(
    [id]           INT NOT NULL IDENTITY(1, 1),
    [name]         NVARCHAR(300) NOT NULL,
    [createdby]    NVARCHAR(4000) NULL,
    [createddate]  DATETIME NULL,
    [modifiedby]   NVARCHAR(4000) NULL,
    [modifieddate] DATETIME NULL
);

GO
......
-- Intitial data population

SET IDENTITY_INSERT [user_profiles] ON;
GO
INSERT INTO [user_profiles] ...........

SET IDENTITY_INSERT [user_profiles] OFF;
GO

INSERT INTO [webpages_Membership] .............
GO

SET IDENTITY_INSERT [webpages_Roles] ON;
GO

INSERT INTO [webpages_Roles] ..............
GO
SET IDENTITY_INSERT [webpages_Roles] OFF;
GO

INSERT INTO [webpages_UsersInRoles] ...........
GO

NOTE0: I have not any table like EdmMetadata or something like that (it was not created upon start, so I have not script for it). I am not guru of EF and I assume that Code First approach does not required any metadata (am I right?).

NOTE1: Of course all other classes/tables required by context created =)

NOTE2: May be I did something wrong with IDENTITY during data population? All string touchs the IDENTITY are here.

Problem: When I trying to save Group I get an exception “The member with identity ‘id’ does not exist in the metadata collection. Parameter name: identity” How to fix it?

  • 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-16T08:48:38+00:00Added an answer on June 16, 2026 at 8:48 am

    I found it! Solution was simple: never mix attribute-way metadata declaration and fluent-api-way.
    I just removed

      [Key]
      [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    

    from Id declaration and changed all model declarations in OnModelChanging like:

    modelBuilder.Entity<MCQGroup>()
        .HasKey(t0 => t0.Id)
        .Map(m => m.ToTable("groups"))
        .Property(x => x.Id)
        .HasColumnName("id")
        .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
        .IsRequired();
    modelBuilder.Entity<MCQGroup>()
        .HasMany(t1 => t1.Sections)
        .WithMany(t2 => t2.Groups)
        .Map(m => m.MapLeftKey("group_id").MapRightKey("section_id").ToTable("groups_to_sections"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class hierarchy class Test { public string Name { get;
I have an hierarchy of classes that looks like the following: class Critical {
I heave roughly speaking the following hierarchy class Base { public: virtual int value()
Suppose I have the following class hierarchy: class A { int foo; virtual ~A()
I have something like following: public interface A { .... } public abstract class
I have the following class hierarchy [BsonKnownTypes(typeof(MoveCommand))] public abstract class Command : ICommand {
I have a class hierarchy like this public abstract class CalendarEventBase{} public class TrainingEvent
I have the following class hierarchy: public class Row : ICloneable, IComparable, IEquatable<Row>, IStringIndexable,
I have a hierarchy like the following: case class A(val a: Long, val b:
I have the following class hierarchy. public abstract class ResourceBase { } public abstract

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.