- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
Add computed column to TypedView
Joined: 23-May-2006
Hi, I found a few postings for this, but somehow I'm missing the last step (or more :-)) it seems.
I want to add a column to a TypedView to read a description for a numeric code out of an array.
This is what I have (code is for adapter)
// __LLBLGENPRO_USER_CODE_REGION_START AdditionalMembers
private DataColumn _columnContactTypeDesc;
// __LLBLGENPRO_USER_CODE_REGION_END
// __LLBLGENPRO_USER_CODE_REGION_START AdditionalFields
// be sure to call _fields.Expand(number of new fields) first.
_fields.Expand(1);
_columnContactTypeDesc = new DataColumn("ContactTypeDesc", typeof(System.String), null, MappingType.Element);
_columnContactTypeDesc.ReadOnly = true;
_columnContactTypeDesc.Caption = @"Kontakttyp-Bezeichnung";
this.Columns.Add(_columnContactTypeDesc);
_fields.DefineField(new EntityField2("ContactTypeDesc", null), _fields.Count - 1);
// __LLBLGENPRO_USER_CODE_REGION_END
// __LLBLGENPRO_USER_CODE_REGION_START InitMembers
_columnContactTypeDesc = this.Columns["ContactTypeDesc"];
// __LLBLGENPRO_USER_CODE_REGION_END
// __LLBLGENPRO_USER_CODE_REGION_START AdditionalColumnProperties
internal DataColumn ContactTypeDescColumn
{
get { return _columnContactTypeDesc; }
}
// __LLBLGENPRO_USER_CODE_REGION_END
And in the Row:
// __LLBLGENPRO_USER_CODE_REGION_START CustomTypedViewRowCode
public string ContactTypeDesc
{
get
{
if(IsTypNull()) {
return (System.String)TypeDefaultValue.GetDefaultValue(typeof(System.String));
}
else {
return Globals.ContactTypes[this.Type].Description;
}
}
}
// __LLBLGENPRO_USER_CODE_REGION_END
In the examples I found there never was a '_fields.DefineField(...)' for the new field, but if I leave this out I get a 'null-reference exception' when I try to fetch the data.
But with this field I also get an exception, 'Index out of bounds' in SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ
So, what am I missing?
Oh and BTW: I never worked much with datatables at all, so I don't see the association between DataColumn and the property of the row. Where is this done? (Or is it missing? ;-))
Juergen
Joined: 16-Nov-2006
Are you sure this line
Globals.ContactTypes[this.Type].Description;
Isn't actually throwing the index out of bounds exception?
Can you provide a full call stack please when the exception is thrown.
Joined: 23-May-2006
Hi, sorry for the delay.
I get the same error if I don't access an array but just return "foo"; To me it seems the code tries to really fetch my new column...
Here is a stacktrace:
bei SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Boolean relationsSpecified, Boolean sortClausesSpecified) bei SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause) bei SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreatePagingSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) bei SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateSelectDQ(IEntityFields2 fieldsToFetch, IFieldPersistenceInfo[] persistenceInfoObjects, IPredicateExpression filter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchTypedView(IEntityFields2 fieldCollectionToFetch, DataTable dataTableToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchTypedView(IEntityFields2 fieldCollectionToFetch, DataTable dataTableToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates) bei CisComsoft.Applications.Project.Bll.TypedViewClasses.StadtGemeindedatenInfoTypedView.GetCollection(RelationPredicateBucket predicates) in C:\Visual Studio 2005\Projects\CisComsoft\Applications\Project\Cis-Code\TypedViewClasses\StadtGemeindedatenInfoTypedView.cs:Zeile 33. bei CisComsoft.Applications.Project.WinForms.DataForms.StadtGemeindedatenReportViewerForm.OnShowReportClicked(ShowReportClickedEventArgs e) in C:\Visual Studio 2005\Projects\CisComsoft\Applications\Project\WinForms\DataForms\Reports\ReportsStammdaten\StadtGemeindedatenReportViewerForm.cs:Zeile 43. bei CisComsoft.Applications.Project.WinForms.DataForms.ReportViewerBase.reportParameterControl_ShowReportClicked(Object sender, ShowReportClickedEventArgs e) in C:\Visual Studio 2005\Projects\CisComsoft\Applications\Project\WinForms\BaseForms\ReportViewerForm.cs:Zeile 116. bei CisComsoft.Applications.Project.WinForms.BaseForms.ReportParameterControl.OnShowReportClicked(Dictionary`2 parameters) in C:\Visual Studio 2005\Projects\CisComsoft\Applications\Project\WinForms\BaseForms\ReportParameterControl.cs:Zeile 286. bei CisComsoft.Applications.Project.WinForms.BaseForms.ReportParameterControl.showReportButton_Click(Object sender, EventArgs e) in C:\Visual Studio 2005\Projects\CisComsoft\Applications\Project\WinForms\BaseForms\ReportParameterControl.cs:Zeile 258. bei System.Windows.Forms.Control.OnClick(EventArgs e) bei System.Windows.Forms.Button.OnClick(EventArgs e) bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) bei System.Windows.Forms.Control.WndProc(Message& m) bei System.Windows.Forms.ButtonBase.WndProc(Message& m) bei System.Windows.Forms.Button.WndProc(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Joined: 17-Aug-2003
The error is coming from this line: _fields.DefineField(new EntityField2("ContactTypeDesc", null), _fields.Count - 1);
which causes the field list to have a field without persistence info. So the query engine can't proceed and it crashes because it has n+1 fields and n persistence infos.
This description, does it have to be fetched from the db? What's the source of the data for the column exactly ?
Joined: 23-May-2006
Hm, I thought so.
But if I don't define this field, I get a NullReferenceException. Stacktrace:
bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.InsertPersistenceInfoObjects(IEntityField2 field) bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchTypedView(IEntityFields2 fieldCollectionToFetch, DataTable dataTableToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchTypedView(IEntityFields2 fieldCollectionToFetch, DataTable dataTableToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates) bei CisComsoft.Applications.Project.Bll.TypedViewClasses.StadtGemeindedatenInfoTypedView.GetCollection(RelationPredicateBucket predicates) in C:\Visual Studio 2005\Projects\CisComsoft\Applications\Project\Cis-Code\TypedViewClasses\StadtGemeindedatenInfoTypedView.cs:Zeile 33. bei CisComsoft.Applications.Project.WinForms.DataForms.StadtGemeindedatenReportViewerForm.OnShowReportClicked(ShowReportClickedEventArgs e) in C:\Visual Studio 2005\Projects\CisComsoft\Applications\Project\WinForms\DataForms\Reports\ReportsStammdaten\StadtGemeindedatenReportViewerForm.cs:Zeile 43. bei CisComsoft.Applications.Project.WinForms.DataForms.ReportViewerBase.reportParameterControl_ShowReportClicked(Object sender, ShowReportClickedEventArgs e) in C:\Visual Studio 2005\Projects\CisComsoft\Applications\Project\WinForms\BaseForms\ReportViewerForm.cs:Zeile 116. bei CisComsoft.Applications.Project.WinForms.BaseForms.ReportParameterControl.OnShowReportClicked(Dictionary`2 parameters) in C:\Visual Studio 2005\Projects\CisComsoft\Applications\Project\WinForms\BaseForms\ReportParameterControl.cs:Zeile 286. bei CisComsoft.Applications.Project.WinForms.BaseForms.ReportParameterControl.showReportButton_Click(Object sender, EventArgs e) in C:\Visual Studio 2005\Projects\CisComsoft\Applications\Project\WinForms\BaseForms\ReportParameterControl.cs:Zeile 258. bei System.Windows.Forms.Control.OnClick(EventArgs e) bei System.Windows.Forms.Button.OnClick(EventArgs e) bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) bei System.Windows.Forms.Control.WndProc(Message& m) bei System.Windows.Forms.ButtonBase.WndProc(Message& m) bei System.Windows.Forms.Button.WndProc(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
In debugger, looking at _fields of an instance of this view, I can see _entityfields[0]..._entityfields[22] and _entityfields[22] is null. So I thought I somehow have to instantiate it...
I want to get this description out of an array. It's only 3 possible values and probably won't change often, so I thought I could spare a table for this. Of course I could just generate the values via 'CASE WHEN' in the database-view, but if I can avoid duplicating the list of possible values, that would be even better
Joined: 17-Aug-2003
JuergenF wrote:
Hm, I thought so.
But if I don't define this field, I get a NullReferenceException.
yes because you still do the Expand(1)
And which array does contain the values?
Joined: 17-Aug-2003
JuergenF wrote:
Hey - I removed the expand, and now it works! Yippee
But now I'm wondering: in what type of scenario would I want to follow this generated comment:
// be sure to call _fields.Expand(number of new fields) first.
?
Juergen
When you add an expression column, e.g. calculating 2 fields in the set into a new value.