Using Custom Fill Methods on BO


Author
Message
Richard Keller
Richard Keller
StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)
Group: Forum Members
Posts: 84, Visits: 324
 When creating a Custom Fill Method does the Data Retrieval order have to match the Business Object Definition order or will the BO auto map the fields to the properties based on the column names?

Thanks for your help.

Richard

Gary Wynne
Gary Wynne
StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)
Group: Forum Members
Posts: 10, Visits: 40

Hi

> When creating a Custom Fill Method does the Data Retrieval order have to match the Business Object Definition order or will the BO auto map the fields to the properties based on the column names?

I assume you are referring to the order of the columns in your returned result set? If so, it doesn't matter to the SF business object. It will read and write the data to the column in the inner DataTable (referenced by the CurrentDataTable property). As long as they are named the same and are of the same datatype/precision, you will be good to go.

HTH

-=Gary

StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Gary is correct.  The order of the columns in the returned result set does not matter.  Also, the columns returned to not have to exactly match the field properties on the business object.  On a per-column basis, what Gary said is correct... the name and the data type have to match.  But, you can have more or fewer columns in the return result set than the strong typed field properties on the business object.  If you have a property that doesn't have a corresponding column in the DataTable, you cannot access it (because there's no data behind the property), so don't touch it in code if the field is not in the DataTable.  However, if you have a column in the table that doesn't have a field property, you can access it through the .Item (default/indexer) property like this (comes in handy for joins and aggregate fields like COUNTs and such):

myBO("MyField") = "some value" '-- VB

myBO["MyField"] = "some value"; //-- C#

Bradley Marston
Bradley Marston
StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)
Group: Forum Members
Posts: 24, Visits: 119
I have a BO that is mapped to a table. To fill the object I call

the FillbyStoredProc method. The stored proc that is called adds 1 additional field

from another table all seems fine except when i try to call my update stored proc

then I seem to get a data layer exception on this added field, Oddly it does not happen on calling my insert proc

StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Does the AllFieldsList property of your business object contain that field?  Also, what is the full exception that you're getting?  Having the stack trace will help point me in the right direction.
Bradley Marston
Bradley Marston
StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)
Group: Forum Members
Posts: 24, Visits: 119
No the AllFieldsList property  does bot show it as a property

Hete is my select statement form sql server Sp

SELECT cs.*, rs.reseller
 FROM Customers cs JOIN
  Reseller rs ON cs.reseller_UID = rs.reseller_UID
 WHERE Customer_UID = @Customer_UID

If I remove  ",rs.reseller"  Then the save works in edit mode (still do not know why add works)

here is the error dump

DataLayerSavingException
 Invalid column name 'reseller'.
SqlException
 Invalid column name 'reseller'.

Source     : MicroFour StrataFrame Business

Stack Trace:
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   at MicroFour.StrataFrame.Data.DbDataSourceItem.GetDataTable(DbCommand Command, OnChangeEventHandler CallBack)
   at MicroFour.StrataFrame.Data.SqlDataSourceItem.GetDataTable(DbCommand Command, OnChangeEventHandler CallBack)
   at MicroFour.StrataFrame.Data.DbDataSourceItem.GetDataTable(QueryInformation QueryInfo, OnChangeEventHandler CallBack)
   at MicroFour.StrataFrame.Data.DataLayer.GetRowFromServer(DataRow LocalRow)
   at MicroFour.StrataFrame.Data.DataLayer.HandleConcurrencyException(DataRow LocalRow)
   at MicroFour.StrataFrame.Data.SqlDataSourceItem.UpdateRow(QueryInformation QueryInfo, DataRow RowToUpdate, ConcurrencyExceptionHandler ConcurrencyHandler, AddRowErrorHandler RowErrorHandler, Boolean RecreateCommand)
   at MicroFour.StrataFrame.Data.DbDataSourceItem.UpdateRow(QueryInformation QueryInfo, DataRow RowToUpdate, ConcurrencyExceptionHandler ConcurrencyHandler, AddRowErrorHandler RowErrorHandler)
   at MicroFour.StrataFrame.Data.DataLayer.UpdateDataTableThread(Object ThreadParams)
   at MicroFour.StrataFrame.Business.BusinessLayer.Save(Boolean Transactional, String TransactionKey)
   at MicroFour.StrataFrame.Business.BusinessLayer.Save()
   at ASTSWITCHTEST.Form1.button7_Click(Object sender, EventArgs e) in C:\strataframetest\ASTSWITCH\ASTSWITCHTEST\ASTSWITCHTEST\Form1.cs:line 93
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

below is the output from

MicroFour.StrataFrame.Data.DataBasics.DataSources["cnDB"].SetDebugOn("C:\\Debug.html", true);


StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
The AllFieldsList is a property on the BusinessLayer class, so, if you put a breakpoint within one of your methods on your business object, you can test the AllFieldsList property to see if it contains "reseller".  When the DAL builds the UPDATE query for a business object, it iterates through the columns on the business object and adds them to the update command only if the column is included in the AllFieldsList of the business object.

The next release also contains some additional functionality for the business objects to allow them to exclude fields from updates.  The feature is currently in testing by a few of our users and will be included in the next release.

Bradley Marston
Bradley Marston
StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)
Group: Forum Members
Posts: 24, Visits: 119

Sorry "No the AllFieldsList property  does bot show it as a property"

Should have said that reselller is not a member of AllFieldsList .

The  AllFieldsList  has 22 memebers of which reselller is not one.

There are 24 variables in  the stored proc @Customer_UID_ORGPK  and   @reseller  are added for strataframe

 

CREATE PROCEDURE UDSP_Customers_Update

 @Customer_UID uniqueidentifier ,  
 @CustomerName varchar(50)      = NULL,
 @CustomerStreet varchar(50)    = NULL,
 @CustomerStreet2 varchar(50)    = NULL,
 @CustomerCity varchar(32)      = NULL,
 @CustomerState char(2)         = NULL,
 @CustomerZIP varchar(9)        = NULL,
 @LCon_Name varchar(50)         = NULL,
 @LCon_Phone varchar(20)        = NULL,
 @LCon_Ext varchar(4)           = NULL,
 @LCon_Mobile varchar(20)       = NULL,
 @LCon_Fax varchar(20)          = NULL,
 @LCon_EmailAddr varchar(80)    = NULL,
 @Status char(16)               = NULL,
 @DealerNum char(7)             = NULL,
 @ODNum char(7)                 = NULL,
 @OD2Num char(7)                = NULL,
 @UpdatedBy varchar(16)               ,  
 @CreatedBy varchar(16)         = NULL,
 @Updateddt datetime            = NULL,
 @Createddt datetime            = NULL,
 @Customer_UID_ORGPK uniqueidentifier = NULL,
 @Reseller_UID uniqueidentifier = NULL,
 -- bellow added for sf
 @reseller varchar(16)         = NULL
)
AS

StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
The image of the debug file that you posted is a little too small to be legible.  Could you zip it and the partial class for your business object and post them here?

Don't post it here if there's a password in the connection string... email it to me through the forum.

Bradley Marston
Bradley Marston
StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)StrataFrame Novice (58 reputation)
Group: Forum Members
Posts: 24, Visits: 119
here are the fileshopfully you will find something.
Attachments
debug.JPG (114 views, 208.00 KB)
BOCust.zip (102 views, 6.00 KB)
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search