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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:44:43+00:00 2026-05-16T14:44:43+00:00

I have a database, and I have entity POCO’s, and all I want to

  • 0

I have a database, and I have entity POCO’s, and all I want to use EF for is to map between the two and keep track of changes for loading, saving, etc.

I have been reading a lot of the literature (such as it is) on “Code First”, and I am unclear on how much of the database information I need to supply when there is not going to be a database generated.

For example, does EF need to know which properties are keys, the maximum length of string properties, the relationships between the tables, etc.? Or if it does need to know, can it get that information from the database itself? In other words, do I have to provide [Key] annotations and such, or provide configuration information detailing the foreign-key relationships, if no database needs to be created?

UPDATE: To make things a little clearer, the following code is what I am talking about. I have to manually create this class derived from DbContext. I could supply a lot of DB information about the properties in OnModelCreating, or in attributes attached to the properties in the entity classes.

    public class SchedulerContext : DbContext
    {
    public SchedulerContext(EntityConnection connection)
        : base(connection)
    {
    }

    public DbSet<Client> Clients { get; set; }
    public DbSet<ConsultantDistrict> ConsultantDistricts { get; set; }
    public DbSet<ConsultantInterviewSetting> ConsultantInterviewSettings { get; set; }
    public DbSet<ConsultantUnavailable> ConsultantsUnavailable { get; set; }
    public DbSet<CustomEmailTemplate> CustomEmailTemplates { get; set; }
    public DbSet<DateEvent> DateEvents { get; set; }
    public DbSet<Event> Events { get; set; }
    public DbSet<EventItem> EventItems { get; set; }
    public DbSet<EventItemUserViewed> EventItemsUserViewed { get; set; }
    public DbSet<FlaggedDate> FlaggedDates { get; set; }
    public DbSet<Interview> Interviews { get; set; }
    public DbSet<Interviewee> Interviewees { get; set; }
    public DbSet<IntervieweeNote> IntervieweeNotes { get; set; }
    public DbSet<InterviewEvent> InterviewEvents { get; set; }
    public DbSet<NotificationSent> NotificationsSent { get; set; }
    public DbSet<SchedulerRole> SchedulerRoles { get; set; }
    public DbSet<SiteEvent> SiteEvents { get; set; }
    public DbSet<UnavailableHour> UnavailableHours { get; set; }
    public DbSet<UserLogin> UserLogins { get; set; }
    public DbSet<UserSites> UserSites { get; set; }
    public DbSet<Visit> Visits { get; set; }

    protected override void OnModelCreating(System.Data.Entity.ModelConfiguration.ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<ConsultantUnavailable>().MapSingleType().ToTable("ConsultantsUnavailable");
        modelBuilder.Entity<EventItemUserViewed>().MapSingleType().ToTable("EventItemsUserViewed");
    }
}
  • 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-16T14:44:43+00:00Added an answer on May 16, 2026 at 2:44 pm

    Yes, the EF does need information on string field lengths, foreign keys, etc., in the model. For example, if a DB FK has a cascade, the EF needs to know that so that it doesn’t force you to manually delete detail records; if the EF is aware of the cascade it will let the DB handle that. Similarly, if the EF is aware that a key is store-generated (e.g., auto-incremented), it won’t complain when you don’t set it on a new record, because it will presume that the DB will do that.

    However, the code-only approach takes a “convention over configuration” approach. You don’t have to specify values which the EF can guess. You can read about those here.

    If you are doing Code Only, the EF doesn’t look at the DB at all when creating the model.

    There is no way to tell the EF to look at code and the DB to create the model. You have to choose one or the other.

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

Sidebar

Related Questions

I have two tables in my database schema that represent an entity having a
I have a database table and a corresponding entity class (POCO with change tracking
I have two tables in my database which have a one-to-one relationship. I want
I have a many-to-many relationship between two entities - Media and MediaCollection. I want
I am attempting to use Entity Framework and have a contact database that has
I'm working on a project in which we have a database, data layer (entity
I have an old database (with terribly named tables and columns) and an entity
I Have an Entity generated from a database table. Then I add a property
I have a real entity Division under database model (EF 4.0). Also I have
I have created an entity data model and generated a database from it. One

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.