U
U
uzi_no_uzi2021-05-04 13:33:02
MySQL
uzi_no_uzi, 2021-05-04 13:33:02

Why isn't a new EntityFramework table created?

I'm trying to work with EntityFramework.

Installed EntityFramework and Pomello to work in MySQL. I was able to connect to the DB, I created a ShopContext

namespace AutoShop.DB
{
    class ShopContext : DbContext
    {
        public DbSet<Car> Cars { get; set; }
        public DbSet<Mark> Marks { get; set; }

        public ShopContext()
        {
            Database.EnsureCreated();
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseMySQL("server=localhost;database=autodb;user=root;password=******");
        }


    }
}


public DbSet<Car> Cars { get; set; }- This part works well, I have a table that I can work with automatically, based on my model

Here is my model:
namespace AutoShop.MVVM.Model
{
    class Car : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged([CallerMemberName] string prop = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
        }


        private int _ID;
        public int ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
                OnPropertyChanged();
            }
        }

        private string _Model;
        public string Model
        {
            get
            {
                return _Model;
            }
            set
            {
                _Model = value;
                OnPropertyChanged();
            }
        }

        private string _Mark;
        public string Mark
        {
            get
            {
                return _Mark;
            }
            set
            {
                _Mark = value;
                OnPropertyChanged();
            }
        }

        private float _Volume;
        public float Volume
        {
            get
            {
                return _Volume;
            }
            set
            {
                _Volume = value;
                OnPropertyChanged();
            }
        }

        private int _DateOfIssue;
        public int DateOfIssue
        {
            get
            {
                return _DateOfIssue;
            }
            set
            {
                _DateOfIssue = value;
                OnPropertyChanged();
            }
        }


        private string _EngineType;
        public string EngineType
        {
            get
            {

                return _EngineType;
            }
            set
            {
                _EngineType = value;
                OnPropertyChanged();
            }
        }

        private string _ImageUrl;

        public string ImageUrl
        {
            get
            {
                return _ImageUrl;
            }
            set
            {
                _ImageUrl = value;
                OnPropertyChanged();
            }
        }

        private int _Price;
        public int Price
        {
            get
            {
                return _Price;
            }
            set
            {
                _Price = value;
                OnPropertyChanged();
            }
        }

        public Car()
        {

        }
    }
}


Next I have another model:
namespace AutoShop.MVVM.Model
{
    class Mark : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged([CallerMemberName] string prop = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
        }


        private int _ID;
        public int ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
                OnPropertyChanged();
            }
        }

        private string _MarkName;

        public string MarkName
        {
            get
            {
                return _MarkName;
            }
            set
            {
                _MarkName = value;
                OnPropertyChanged();
            }
        }
        public Mark()
        {

        }
    }
}


There are already problems with this model, although I do everything in the same way as the first one.

Writes that the marks table is not created. The question is why did EntityFramework create one table automatically and the second one didn't.
60912404763f4844474110.png

What could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question