This question is locked. New answers and comments are not allowed.
Hello!
I am working in VS2012, WindowsForms application, TargetFwk = 4.5 and trying to bind a DataGridView control to a collection that allows the grid to automatically handle add and remove from the collection. I tried ObservableCollection<T> as it implements INotifyCollectionChanged and seems a good candidate to what I am trying to achieve.
I have a Document which has DocumentDetails, so the grid binds to the details. What I've done:
1) created a copy of the generation templates within the solution and customized collection generation (ObservableCollection<T> instead of IList<T>) as indicated by Telerik here
After customization details property looks like this (within Document entity - generated code):
private ObservableCollection<DocumentDetail> _documentDetails = new ObservableCollection<DocumentDetail>();
[Collection(InverseProperty = "Document")]
[Storage("_documentDetails")]
public virtual ObservableCollection<DocumentDetail> DocumentDetails
{
get
{
return this._documentDetails;
}
}
instead of the classical one
private IList<DocumentDetail> _documentDetails = new IList<DocumentDetail>();
[Collection(InverseProperty = "Document")]
[Storage("_documentDetails")]
public virtual IList<DocumentDetail> DocumentDetails
{
get
{
return this._documentDetails;
}
}
2) The solution loads and existing document having several details by:
i) load: theDoc = context.Documents.Where(
d => d.DocumentId == documentId).FirstOrDefault();
ii) bind: dgDocumentDetails.DataSource = theDoc.DocumentDetails;
Before changing to ObservableCollection<DocumentDetail> i) loads data from Document and ii) loads the details (lazy loading)
After the change i) tries to load everything, but fails because it tries to get data from an nonexistent table:
declare @p1 int
set @p1=-1
exec sp_prepexec @p1 output,N'@p0 int',N'SELECT a.[DocumentId] AS COL1, b.[DocumentId] AS COL2, c.[DocumentDetailId] AS COL3, c.[Amount] AS COL4, c.[DocumentId] AS COL5, c.[DocumentId] AS COL6, c.[TotalAmountWithVAT] AS COL7, c.[VATAmount] AS COL8, b.[seq] AS xj2 FROM [Document] a JOIN [Document_DocumentDetail] AS b ON (a.[DocumentId] = b.[DocumentId]) LEFT JOIN [DocumentDetail] AS c ON (b.[DocumentDetailId] = c.[DocumentDetailId]) WHERE a.[DocumentId] = @p0 ORDER BY COL2, xj2 ',@p0=1
select @p1
Any idea how can I make this work?
Thank you,
Alex D.
I am working in VS2012, WindowsForms application, TargetFwk = 4.5 and trying to bind a DataGridView control to a collection that allows the grid to automatically handle add and remove from the collection. I tried ObservableCollection<T> as it implements INotifyCollectionChanged and seems a good candidate to what I am trying to achieve.
I have a Document which has DocumentDetails, so the grid binds to the details. What I've done:
1) created a copy of the generation templates within the solution and customized collection generation (ObservableCollection<T> instead of IList<T>) as indicated by Telerik here
After customization details property looks like this (within Document entity - generated code):
private ObservableCollection<DocumentDetail> _documentDetails = new ObservableCollection<DocumentDetail>();
[Collection(InverseProperty = "Document")]
[Storage("_documentDetails")]
public virtual ObservableCollection<DocumentDetail> DocumentDetails
{
get
{
return this._documentDetails;
}
}
instead of the classical one
private IList<DocumentDetail> _documentDetails = new IList<DocumentDetail>();
[Collection(InverseProperty = "Document")]
[Storage("_documentDetails")]
public virtual IList<DocumentDetail> DocumentDetails
{
get
{
return this._documentDetails;
}
}
2) The solution loads and existing document having several details by:
i) load: theDoc = context.Documents.Where(
d => d.DocumentId == documentId).FirstOrDefault();
ii) bind: dgDocumentDetails.DataSource = theDoc.DocumentDetails;
Before changing to ObservableCollection<DocumentDetail> i) loads data from Document and ii) loads the details (lazy loading)
After the change i) tries to load everything, but fails because it tries to get data from an nonexistent table:
declare @p1 int
set @p1=-1
exec sp_prepexec @p1 output,N'@p0 int',N'SELECT a.[DocumentId] AS COL1, b.[DocumentId] AS COL2, c.[DocumentDetailId] AS COL3, c.[Amount] AS COL4, c.[DocumentId] AS COL5, c.[DocumentId] AS COL6, c.[TotalAmountWithVAT] AS COL7, c.[VATAmount] AS COL8, b.[seq] AS xj2 FROM [Document] a JOIN [Document_DocumentDetail] AS b ON (a.[DocumentId] = b.[DocumentId]) LEFT JOIN [DocumentDetail] AS c ON (b.[DocumentDetailId] = c.[DocumentDetailId]) WHERE a.[DocumentId] = @p0 ORDER BY COL2, xj2 ',@p0=1
select @p1
Any idea how can I make this work?
Thank you,
Alex D.