一个dataGridView中的两个实体 [英] Two entities in one dataGridView
问题描述
pg = new PGEntities();
BindingList< Zamow>我的列表;
var query =(from zam in pg.Zamow where zam.Rok == 2012 select zam).Take(100);
MyList = new BindingList< Zamow>(query.ToList());
zamowBindingSource.DataSource = MyList;
是的,尝试创建 Class
,说一个 ViewZamowAndSamSkany
public class ViewZamowAndSamSkany
{
公共字符串Data {get;组; }
public string Proforma {get;组; }
//和其他属性
}
现在,重建你的项目并从对象数据源
中添加 ViewZamowAndSamSkany
然后拖放到您的表单
作为
DataGridView
,您可以应用linq-entites inner join
var query =(从zam在pg.Zamow
在zam.NUMBER中加入skany等于skany.NUMBER
其中zam.Rok == 2012
选择新的ViewZamowAndSamSkany
{
Data = zam.Data,
Proforma = zam.Proforma
})Take(100);
MyList = new BindingList< ViewZamowAndSamSkany>(query.ToList());
zamowBindingSource.DataSource = MyList;
I have two entites with association. I create a dataGridView by drag and drop from objects Data Source and manually binding from to list. Everything works fine with one entity. Is there any possibility of create one dataGridView with two entities(Zamow and ZamSkany) by drag and drop + manually filling? I can do this by view (on SQL side) but in same cases I'd like to have other possibilities.
pg = new PGEntities();
BindingList<Zamow> myList;
var query = (from zam in pg.Zamow where zam.Rok == 2012 select zam).Take(100);
MyList = new BindingList<Zamow>(query.ToList());
zamowBindingSource.DataSource = MyList;
Yes, try to create Class
, let say a ViewZamowAndSamSkany
public class ViewZamowAndSamSkany
{
public string Data { get; set; }
public string Proforma { get; set; }
//and Others Properties
}
and now, rebuild your project and from the Objects Data Source
add the ViewZamowAndSamSkany
then drag-drop to your Form
as a DataGridView
and you can apply the linq-entites inner join
var query = (from zam in pg.Zamow
join skany in zam.NUMBER equals skany.NUMBER
where zam.Rok == 2012
select new ViewZamowAndSamSkany
{
Data = zam.Data,
Proforma = zam.Proforma
}).Take(100);
MyList = new BindingList<ViewZamowAndSamSkany>(query.ToList());
zamowBindingSource.DataSource = MyList;
这篇关于一个dataGridView中的两个实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!