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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:15:24+00:00 2026-06-08T23:15:24+00:00

I just wanted to try Entity Framework to use it instead of NHibernate. I’m

  • 0

I just wanted to try Entity Framework to use it instead of NHibernate. I’m using a MySql database.
So I did few tests with the code first system. Everything is ok with MsSql the database and the schema is auto generated. But then I tried it with MySql and the schema generation doesn’t work.

public class Context : DbContext
{
    public Context()
    {

    }

    public Context(string str)
        : base (str)
    {

    }

    public DbSet<User> Users
    {
        get;
        set;
    }
}

public class User
{
    public int Id
    {
        get;
        set;
    }

    public string Name
    {
        get;
        set;
    }
}

class Program
{
    static void Main(string[] args)
    {
      var sqlBuilder =
            new SqlConnectionStringBuilder
            {
                DataSource = "localhost",
                InitialCatalog = "test",
                Password = "",
                UserID = "root"
            };

        var entityBuilder =
            new EntityConnectionStringBuilder
            {
                Provider = "MySql.Data.MySqlClient",
                ProviderConnectionString = sqlBuilder.ConnectionString,
                Metadata = @"res://*"
            };

        var str = entityBuilder.ConnectionString;

        using (var ctx = new Context(str)) 
        {

            ctx.Users.Add(new User() // exception here
            {
                Name = "test"
            });

            ctx.SaveChanges();
        }

        using (var ctx = new Context(str))
        {
            foreach (var user in ctx.Users)
            {
                Console.WriteLine("id:{0} name:{1}", user.Id, user.Name);
            }
        }
    }
}

And I got this exception : “The entity type User is not part of the model for the current context.”

So here is my question, can I generate the database automatically if I use MySql ?

  • 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-08T23:15:27+00:00Added an answer on June 8, 2026 at 11:15 pm

    I dunno why it works but it does now. I removed the connection properties from the code and I’ve created an app.config file and correct a bug at the database creation with this blog http://brice-lambson.blogspot.fr/2012/05/using-entity-framework-code-first-with.html and now it works

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

Sidebar

Related Questions

I just wanted to try out SPDY using the node package node-spdy. My javascript:
I just discovered forge and wanted to try it out at once. I closely
I just started out with Python and wanted to try out tornado. Running the
Just wanted to know if anyone is really using Objects and Collections in Oracle
I just wanted to try out some shaders on a flat image. Turns out
I am currently using Eclipse 3.5.0 for Android development. But I just wanted to
NOTE: The scenario is using 2 entity framework models to sync data between 2
Trying to use $SAFE=1 (just wanted to put some processing in a drb server)
i am fooling around with the new entity framework, and just for fun io
I just wanted to try out this code... #include <iostream> #include <stdio.h> #include <string.h>

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.