I am trying to get information from a related many-to-many two tables to a column. There are two classes for accounting for mobile devices and their IMEI: CDevice and ImeiList.
public partial class CDevice { public CDevice() { this.ImeiList = new HashSet<ImeiList>(); } public int Id { get; set; } public string Model { get; set; } public string Title { get; set; } public virtual ICollection<ImeiList> ImeiList { get; set; } } public partial class ImeiList { public ImeiList() { this.CDevice = new HashSet<CDevice>(); } public int Id { get; set; } public long IMEI { get; set; } public virtual ICollection<CDevice> CDevice { get; set; } } There is a collection in the ViewModel:
private static ObservableCollection<CDevice> _oCollDevice; public static ObservableCollection<CDevice> OCollDevice { get { if (_oCollDevice == null) _oCollDevice = new ObservableCollection<CDevice>(); return _oCollDevice; } } As well as two methods, one of which receives information from the database:
public static List<CDevice> GetDeviceList() { using (DevicesEntities context = new DevicesEntities()) { context.Configuration.LazyLoadingEnabled = false; var deviceList = context.CDeviceSet. Include("ImeiList").ToList(); return deviceList; } } And the second one calls it and adds the resulting list to the collection:
private void GetDevices() { var CdeviceResult = GetDeviceList(); OCollDevice.Clear(); foreach (var item in CdeviceResult) { OCollDevice.Add(CurrentDevice); } } With ViewModel via Datacontext there is a View in which there is a Datagrid
<DataGrid ItemsSource="{Binding Path=OCollDevice}" AutoGenerateColumns="False" Width="auto" HorizontalScrollBarVisibility="Disabled" > <DataGrid.Columns> <DataGridTextColumn Header="Наименование (производитель)" Binding="{Binding Path=Title}"></DataGridTextColumn> <DataGridTextColumn Header="Модель" Binding="{Binding Path=Model}"></DataGridTextColumn> <DataGridTextColumn Header="IMEI" Binding="{Binding Path=ImeiList.IMEI, Mode=OneWay}"></DataGridTextColumn> </DataGrid.Columns> </DataGrid> Question: how to display information in this table, so that all IMEIs and their corresponding devices are displayed, and that all devices and the corresponding IMEIs are displayed. Now in the column "IMEI" is empty, although the collection takes into account the number of matching IMEI and through PROFILER you can see the LEFT OUTER JOIN, which displays the necessary information. How to pull in a table IMEI?
ICollection<ImeiList>does not contain theIMEIproperty, so nothing is displayed. In what form do you want to display this collection in a single table cell? - Andrey NOPCDevice, how do you want to display them in one cell of the table? - Andrew NOP