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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:02:42+00:00 2026-06-02T05:02:42+00:00

There are many tutorials on Fluent API, but they all explain it using Entity

  • 0

There are many tutorials on Fluent API, but they all explain it using Entity Framework Code-First code examples. Since I don’t know Code-First, do you know of any Fluent API tutorials that would explain the subject using EF Database-First approach?

Thank you

  • 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-02T05:02:43+00:00Added an answer on June 2, 2026 at 5:02 am

    There are no tutorials which would explain the Fluent API together with Database-First approach because Fluent API is made only for Code-First approach. You don’t need the Fluent API if you want to create your model via Database-First.

    Fluent API (together with Code-First data annotations and conventions) is a tool to define model details in code, such as string length, if a property is required or the type of relationship – many-to-many, one-to-many, etc. When using Database-First or Model-First the EDMX file has the same purpose – it contains all the details and mapping definitions of your model. Fluent API (+ data annotations and conventions) replaces the EDMX file only when using Code-First.

    If you create the model via Database-First or Model-First, you will have an EDMX file representing your model. You can apply the T4 DbContext Generator to this EDMX file. The generated files have two characteristics being different from Code-First:

    • The generated connection string contains a section refering to the EDMX metadata which will be embedded into your assembly:

      connectionString="metadata=res://*/Model.csdl
                                |res://*/Model.ssdl
                                |res://*/Model.msl;
                        ..."
      
    • The generated context DbContext will have an overridden OnModelCreating method which just throws an exception:

      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          throw new UnintentionalCodeFirstException();
      }
      

    As long as you leave the metadata section in the connection string, EF won’t even call OnModelCreating or any code in Fluent API in this method. The metadata section tells EF that your model is DB- or Model-First and that the metadata are defined in the embedded EDMX and not in Fluent API.

    However, you can remove the metadata section from the connection string, remove the UnintentionalCodeFirstException and write code with Fluent API in OnModelCreating. You can follow this procedure to create an initial model via Database-First and then build on this initial model for further development with Code-First.

    At this point you are not working anymore with Database-First, but Code-First instead and everything you read about Fluent API is valid for you.

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

Sidebar

Related Questions

I am using vbulletin 4.1.7 I've read many tutorials out there but none explais
I know there are many tutorials on OpenGL out there, but all good tutorials
I know there are many tutorials to use Dropbox as a Git repository, but
There are many things that all programmers should know, but I am particularly interested
I see there are many tutorials about nhibernate but I cannot find a descent
There have been many tutorials where each suggests using gluPerspective or glFrustum with a
I've looked at many tutorials but all of them are too confusing or outdated.
There are many tutorials that talk about deleting index.php from the url. But I
I wanted to give a try to razor but there are not many tutorials
i tried many tutorials but all failed, i know for an experienced user it

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.