如何添加我借出的物品数量栏?

时间:2019-02-26 12:02:17

标签: c# visual-studio entity-framework datagridview many-to-many

我想添加一个列,该人提供的项目数量 预先感谢

BindingSource bindingSource1 = new BindingSource();

bindingSource1.DataSource = (from l in db.Loans.Where(item => item.Items.Any())
                                         from i in db.Items.Where(loan => loan.Loans.Contains(l))
                                         from p in db.People.Where(person => person.Id == l.PersonId)
                                         select new
                                         {
                                             p.FirstName,
                                             l.LoanId,
                                             i.ItemId,
                                             i.ItemName
                                         }).ToList();


            dataGridView1.DataSource = bindingSource1;

我的结果:

result

1 个答案:

答案 0 :(得分:0)

我在网络上找不到任何东西,例如...实际可行的任何东西! 所以我编辑了数据库->我在“表格之间”添加了一列,添加了QuantityLoaned

My database

然后我必须对代码进行一些更改,现在看起来像这样:

BindingSource bindingSource1 = new BindingSource();

bindingSource1.DataSource = (from l in db.LoanItems.Where(item => item.Item.LoanItems.Any())
                                         from p in db.People.Where(person => person.Id == l.Loan.PersonId)
                                         orderby l.LoanId ascending
                                         select new
                                         {
                                             p.Id,
                                             p.FirstName,
                                             l.LoanId,
                                             l.Item.ItemId,
                                             Dagenoud = SqlFunctions.DateDiff("Weekday", l.Loan.StartDate, DateTime.Now),
                                             l.QuantityLoaned
                                         }).ToList();


            dataGridView1.DataSource = bindingSource1;

这给了我下一个结果:

My result