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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:06:11+00:00 2026-05-25T21:06:11+00:00

I have a type called TypeA and somewhere in TypeA there is a property

  • 0

I have a type called TypeA and somewhere in TypeA there is a property of TypeB (which contains nothing other than an ID and String).

Using Entity Framework, I have created a DbSet of TypeA – public DbSet<TypeA>.

This creates the TypeB column in the database just fine – however, I now need to seed some data. As TypeB does not exist in the original DbContext, I am unable to seed data to it.

I therefore added public DbSet<TypeB> to my original DbContext and it didn’t even detect a change/difference in the Database schema.

So, this got me wondering, and my question is, Is there any difference in creating a separate DbSet over one that is automatically created by a relation?

Sample Code

  public class TypeA
    {

        public int id { get; set; }


        public string name { get; set; }


        public TypeB foo { get; set; }
    }

    public class TypeB
    {
        public int ID { get; set; }

        public string name { get; set; }
    }
  • 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-25T21:06:11+00:00Added an answer on May 25, 2026 at 9:06 pm

    Yes, there is a difference.

    In design terms, the point of the DbSet class is to embody the Repository pattern:

    Conceptually, a Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer. Repository also supports the objective of achieving a clean separation and one-way dependency between the domain and data mapping layers.

    Its purpose is to encapsulate CRUD for a given entity. In order to do this the repository can’t limit itself to just one table. Sometimes it must work with an object tree in the DB.

    In your case, having a DbSet for both types will give you a repository to directly access that entity. This will allow you to query directly for TypeB or directly create/update TypeB instances in the DB, rather than always having to always root your queries in TypeA.

    Some of this depends on your associations, though. If you have a constraint on TypeB that requires a TypeA, then you can’t create them without a TypeA. However you can still query for them directly.

    You can still create or update TypeB instances without the DbSet<TypeB> – simply attach one to the TypeA instance and work against the the DbSet<TypeA>.

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

Sidebar

Related Questions

I have a class with a Property called 'Value' which is of type Object.
I'm using VS2010 Beta 2, I have a Complex Type called Address with the
I have a class called Question that has a property called Type. Based on
I have a table which has a column called Direct of type char(1). It's
I have this mysql table called comments which looks like this: commentID parentID type
I have content type called event, which has a cck field called event id.
I have a content type called fund. The contents of this is in node-fund.tpl.php
I have a column of type Bit (called BBoolVal in this example). I have
I have a products table with a column of type SET (called especialidad), with
In mysql database i have this column called: Name: Date Type: datetime I have

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.