Сама ошибка:
System.Data.Entity.ModelConfiguration.ModelValidationException: "One or more validation errors were detected during model generation:
CalculatorMaining.Classes.video_card: : EntityType 'video_card' has no key defined. Define the key for this EntityType.
video_cards: EntityType: EntitySet 'video_cards' is based on type 'video_card' that has no keys defined.
Код Модели
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace CalculatorMaining.Classes
{
[Table("video_cards")]
class video_card
{
[Key]
private string model;
private double consumption, income;
public double Consumption
{
get { return consumption; }
set{ consumption = value;}
}
public double Income
{
get { return income; }
set { income = value; }
}
public video_card() { }
public video_card(double consumption, double income, string model)
{
this.consumption = consumption;
this.income = income;
this.model = model;
}
}
}
Код Контекста
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
namespace CalculatorMaining.Classes
{
class ApplicationContext : DbContext
{
public DbSet<video_card> video_cards { get; set; }
public ApplicationContext() : base("DefaultConnection") { }
}
}
код мейна
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CalculatorMaining.Classes;
namespace CalculatorMaining
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Classes.ApplicationContext db;
public MainWindow()
{
InitializeComponent();
db = new Classes.ApplicationContext();
}
private void startButton_Click(object sender, RoutedEventArgs e)
{
video_card video_card = new video_card();
db.video_cards.Add(video_card);
db.SaveChanges();
}
}
}