Answer the question
In order to leave comments, you need to log in
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 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()
{
}
}
}
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()
{
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question