我已经阅读了许多有关此问题的主题,但我仍然无法理解为什么会出现此错误。
抛出标题中提到的错误:db.megrendelesek.Add(form.uj);
private void button1_Click(object sender, EventArgs e)
{
foreach (Account item in db.accountok)
{
if (item.Username == textBox1.Text && item.Password == textBox2.Text)
{
MegrendelesForm form = new MegrendelesForm(item as Account);
if (form.ShowDialog() == DialogResult.OK)
{
db.megrendelesek.Add(form.uj);
db.SaveChanges();
}
}
else
{
MessageBox.Show("Bad user or pw");
}
}
}
public partial class MegrendelesForm : Form
{
RaktarDB db = new RaktarDB();
public Megrendeles uj { get; set; }
public Account belepett = new Account();
public MegrendelesForm(Account item)
{
InitializeComponent();
belepett = item;
var aruk = (from aru in db.aruk
select aru).ToList<Aru>();
listBox1.DataSource = aruk;
}
private void button1_Click(object sender, EventArgs e)
{
List<Aru> aruk = new List<Aru>();
foreach (Aru item in listBox2.Items)
{
aruk.Add(item);
}
uj = new Megrendeles {account=belepett,aruk=aruk };
}
public class Megrendeles
{
public int ID { get; set; }
public virtual Account account { get; set; }
public virtual List<Aru> aruk { get; set; }
}
}