StrataFrame Forum

Using Custom Fill Methods on BO

http://forum.strataframe.net/Topic5597.aspx

By Richard Keller - 1/4/2007

 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

By Gary Wynne - 1/5/2007

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

By StrataFrame Team - 1/5/2007

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#

By Bradley Marston - 1/24/2007

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

By StrataFrame Team - 1/24/2007

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.
By Bradley Marston - 1/25/2007

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);

By StrataFrame Team - 1/25/2007

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.

By Bradley Marston - 1/25/2007

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
By StrataFrame Team - 1/25/2007

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.

By Bradley Marston - 1/25/2007

here are the fileshopfully you will find something.
By StrataFrame Team - 1/25/2007

Are you trying to update the Reseller.reseller field?  Or are you trying to just update the fields within the Customers table?
By Bradley Marston - 1/25/2007

No I am just trying to do an update in the customers table

the Reseller field from the Select Was used by another apllication

CREATE PROCEDURE UDSP_Customers_GetData
 (  
  @Customer_UID uniqueidentifier = NULL
 Wink
AS

SET NOCOUNT ON

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

_________________________________________________________________

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,
 @reseller varchar(16)         = NULL
)
AS

SET NOCOUNT ON

UPDATE customers SET   
  CustomerName    = ISNULL(@CustomerName, CustomerName),
  CustomerStreet  = ISNULL(@CustomerStreet, CustomerStreet),
  CustomerStreet2  = ISNULL(@CustomerStreet2, CustomerStreet2),
  CustomerCity    = ISNULL(@CustomerCity, CustomerCity),
  CustomerState   = ISNULL(@CustomerState, CustomerState),
  CustomerZIP     = ISNULL(@CustomerZIP, CustomerZIP),
  LCon_Name       = ISNULL(@LCon_Name, LCon_Name),
  LCon_Phone      = ISNULL(@LCon_Phone, LCon_Phone),
  LCon_Ext        = ISNULL(@LCon_Ext, LCon_Ext),
  LCon_Mobile     = ISNULL(@LCon_Mobile, LCon_Mobile),
  LCon_Fax        = ISNULL(@LCon_Fax, LCon_Fax),
  LCon_EmailAddr  = ISNULL(@LCon_EmailAddr, LCon_EmailAddr),
  Status          = ISNULL(@Status, Status),
  DealerNum       = ISNULL(@DealerNum, DealerNum),
  ODNum           = ISNULL(@ODNum, ODNum),
  OD2Num          = ISNULL(@OD2Num, OD2Num),   
  Reseller_UID    = ISNULL(@Reseller_UID, Reseller_UID),  
  UpdatedBy            = UpdatedBy, 
  UpdatedDt            = GETDATE()

 WHERE Customer_UID    = @Customer_UID

By StrataFrame Team - 1/25/2007

OK, you can remove the @reseller field from the update command.  The business object will only attempt to update fields that are part of the mapped table (those contained in the AllFieldsList).  Since your business object was mapped to Customers, it does not think that @reseller should be supplied because it doesn't think it's part of the updating table.  So, whatever the structure of the data table inside the business object, it's only going to update the fields that are part of the mapped table on SQL Server.
By Bradley Marston - 1/25/2007

Taking the variable out of the SP does not change anything

the only way to make it work is to change the SP's that get the data and make sure reseller is not in the data returned.

By Trent L. Taylor - 1/25/2007

Are you creating the stored procedure?  If so, what do your CRUD settings look like on your BO?  Last, what does the SP look like?

Note: Please do not post the entire SP text in the text window.  Upload it as an attachment so we can get a more accurate view.