Multiple Tables in an object


Author
Message
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
If you want to override a field property that maps to a field in the database, then you will need to use the Custom Code option within the BOMapper and supply the code that you want it to spit out when it creates the partial class.

If you want to create a second property (instead of replacing the property itself), you'll want to create a new property in the main code file so that it does not get overwritten when the partial class is re-created again.  The easiest way to do this is to copy one of the fields from the designer file, paste it into the main code file (attributes and all) and modify it the way you want it.  Then, just override the GetCustomBindablePropertyDescriptors() method and return the property descriptor for that property.  (You should be able to search either the help or the forum for "GetCustomBindablePropertyDescriptors" because it might show you some more information and show you what happens when you don't provide a descriptor BigGrin).

choyt
choyt
StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)
Group: Forum Members
Posts: 78, Visits: 246
Ok...I put the property in "my part" of the partial class and this seems to have fixed the problem!
choyt
choyt
StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)
Group: Forum Members
Posts: 78, Visits: 246
Hi Folks

I have this working with one caveat.

I have a "Users" table that hold basic inforamtion such as First and Last name but am using forms authentication and want to take full advantage of that so am using the aspnet_ tables as well. To do this, I am joining together my Users table with aspnet_Users and aspnet_Membership. There is no data of use to me in the aspnet_Users table but there is quite a bit of useful info in the membership table.

To do this the way that has been described, I am customizing the UserName field in my user table (the FK to the UserName field in aspnet_Users) and replacing it with a BO that I mapped against aspnet_membership. I would much rather keep my user name field intact but there is no way in the object mapper to create a field. You can only use (override) fields that are aleady part of the underlying database table.

I can see these work arounds

  1. Create a "fake" field in the database to fool the mapper into believing there is an extra field.
  2. Manually modify the designer.vb file each time I do a build (kind of pain but not out of the question)
  3. Overwriting my UserName field.

Is there something simple and basic I'm missing or is my understanding correct?

Thanks! BigGrin

Michael Cobb
Michael Cobb
StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)
Group: Forum Members
Posts: 26, Visits: 1K
Thanks Ben.  I hadn't seen the underscore naming convention except for in the StrataFrame code but I like it and think I will use it as well.
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 underscore is just a convention that we use internally.  It's not a .NET naming convention.  However, with VB, when you create a "Public WithEvents MyField As SomeType" field on your class, VS behind the scenes creates a field named the same as your field, but with an underscore (_MyField) and instead of creating a public field, it wraps the implicit private (_MyField) with a public property. 

Other than that, I don't know of any convention that says that your private fields (or any other member fields) need to start with an _.  We just do because we like the convention.  I've looked through the .NET framework using Reflector a few times, and in most of their stuff, they either start their private fields with an _ and camel case them or just camel case them (_myField or myField).  It's entirely up to you.

I can't find the MSDN page that lists the .NET naming conventions, but this guy has most of them listed.  Look down at the one that says "Class-Level Private and Protected Variables"

http://www.irritatedvowel.com/Programming/Standards.aspx

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Thanks a lot for this Robert. I'll file it away for when my SF level rises BigGrin
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)Advanced StrataFrame User (952 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Thanks Ben - I knew it wasn't part of the Strataframe Sample Data but it was referenced in the zip you posted so I thought you might have used his XSD to add the tables to the sample data in some way everyone but me knew about "Smile
Michael Cobb
Michael Cobb
StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)
Group: Forum Members
Posts: 26, Visits: 1K
Ben,

In the following declaration statement what is the naming convention calling for the variable name to begin with an underline?  Is this typically used for property variables?

Private WithEvents _State As New StateBO()


Michael Cobb
Michael Cobb
StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)StrataFrame Beginner (36 reputation)
Group: Forum Members
Posts: 26, Visits: 1K
Charles:  The way I did this was to add a State table to the SF Sample database.  The table consists of StateName and StateCode columns.  StateName has the long names and StateCode has the abbreviations.  Then I went into the VB.NET CRMApplication sample.  I added a BO called StateBO to that project and used the BusinessObjectMapper to create the partial class for it. 

I added the following custom code to the StateBO for a parameterless data retrieval method:

''' <summary>

''' Fills the business object with all records order by primary key

''' </summary>

''' <remarks></remarks>

Public Sub FillAllStateTable()

'-- Establish local

Dim loCommand As New SqlCommand()

'-- Create the command

loCommand.CommandText = "SELECT * FROM State ORDER BY StateCode"

'-- Execute the command

Me.FillDataTable(loCommand)

End Sub

#End Region

Then I modified the custom code for the CustomersBO by adding the following lines of code only:

Private WithEvents _State As New StateBO()

''' <summary>

''' This method handles the Navigated event of the Customers business object to allow

''' you to set the filter on the State business object.

'''

''' You can filter the StateBO to only show records that match the current record

''' within the CustomersBO.

''' </summary>

''' <param name="e"></param>

Private Sub CustomersBO_Navigated(ByVal e As MicroFour.StrataFrame.Business.NavigatedEventArgs) Handles Me.Navigated

'-- Set the filter on the internal StateBO

' (Only necessary if the CompanyBO will contain more than one record)

Me._State.Filter = "StateCode = '" & CType(Me.CurrentRow("cust_State"), String) & "'"

End Sub

Next I did a BuildAll so that the Company and State Business Objects were recompiled.

To test it, I moved the State Textbox (Textbox9) to the bottom of the form (you could just as easily remove it) and replaced it with a StrataFrame ComboBox on which I set the following properties: BusinessObject=Customers, BindingField = cust_State, DropDownStyle=DropDownList, PopulationType=BusinessObject, PopulationDataSourceSettings=StateBO.FillAllStateTable().  The PopulationDataSourceSettings property gets built by clicking the ellipsis on the property.  Inside there I put {0} under Display Member and Drop-Down Display, StateName under ValueMember and added StateCode to DisplayMember.

When you run the form the combo box will display the state code for the current record as you browse.  If you edit/add a record the combo box displays a list of all possible state codes.  If you change a value and save it, the Customers table will save the state name associated with the state code.

That should get you started if you're still looking at this.

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
Ah, I gotcha... the XSD that Robert posted is not part of the StrataFrameSample database... it was something else that he was working on (or maybe he modified his sample database, I dunno).  So, it's starting to make sense why you thought that the XSD he posted was part of the SF sample. 

I'm glad you found a few tools to convert the XSDs and so forth.  But just remember, the only 2 sources of structures for the BOMapper are the DDT and the database itself on the server.

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