New to CLSA
Old forum URL: forums.lhotka.net/forums/t/345.aspx
qwerty123 posted on Monday, June 12, 2006
Hi group,
I am new to CLSA.NET. I would like to adopt it in a new application I am developing. I saw the sample application from Lhotka. Is there any another sample applications with the CSLA platform. I have some issues which I need to resolve before starting.
Thanks
ajj3085 replied on Monday, June 12, 2006
What issues do you need to resolve exactly?
We all have working applications built on top of Csla, but I'm not sure any of us could post the entire application.
Andy
qwerty123 replied on Monday, June 12, 2006
Let me give you an example
Tables
Items: a list of inventory items with ItemID as the PK
Invoice: The invoice header which has a field InvoiceID as the PK
InvoiceItems: has a list of items on a invoice with ItemID and InvoiceID as the PK. InvoiceID is a FK for Invoice and ItemID is a FK for Items.
Now I have another table ItemsDetails which is basically the same as the InvoiceItems, but I have more information in this table so there is one to one relationship between InvoiceItems and ItemDetails.
How do I setup my classes.
Items: BusinessBase
Invoice: BusinessBase
InvoiceItems: ???
ItemDetails: ???
Where do i write the SQL Insert and Update Code???
ajj3085 replied on Monday, June 12, 2006
Well,
First, you ignore your database tables and go get your requirements or use cases.
Design the classes around what you need to do with an invoice. You'll likely have an Invoice class which supports editing, and another who's purpose is just to display data. You may need other classes for other, completely different behaviors for the Invoice.
To answer your database code question; these belong within the DataPortal_ZZZ methods, depending on the data operation. But worry about getting data into and out of the database after you defined your objects.
HTH
Andy
qwerty123 replied on Monday, June 12, 2006
Thanks for replying.
What I am refering now is for an invoice class to hold information about the invoice and allow to update the invoice and it's details.
What I am not clear is if one class can update more than 1 table. Example when saving a invoice item can the class update to more than 1 table or I would need to create a new class for each table???
For the example above I know what type of classes I need to create
- Invoice = BusinessBase
- Item = BusinessBase
- InvoiceItem: ??? Is this also a BusinessBase
- InvoiceItems: BusinessCollectionBase
- ItemDetails: ??? Is this a child of InvoiceItem even if it's a one to one relationship or this is another BusinessCollectionBase on Invoice or can I ignore this and combine with InvoiceItem. However for updating the database I would need 2 seperate update and fetch statements in the InvoiceItem Class
???????
Please help I am not sure if I am clear enough
ajj3085 replied on Monday, June 12, 2006
Yes, one class can do whatever it wants to in the database, although the LineItems should probably be responsible for persisting themselves.
The DataPortal code doesn't make any assumptions about what you might do for data access.
Your invoiceitem would likely inherit from BusinessBase. I'm not sure what ItemDetails would do. Could you describe its behavior? I doubt you need such a class for the purpose of editing an invoice. You may need it for keeping the product data up to data though.
qwerty123 replied on Monday, June 12, 2006
Thanks.
The Invoiceitems and the ItemDetails tables are basically a one to one relationship and both have a InvoiceID and ItemID which are FK to Invoice and Items table. However the InvoiceItems has only the junction information and the rest of data is in the ItemDetails. Every record in InvoiceItems would have a record in ItemDetails (I KNOW I CAN COMBINE BOTH TABLES, HOWEVER THIS IS THE WAY I NEED IT NOW) so it's basically one object InvoiceItem but in the database it's split so do I need a new object for each table or I can combine into one, and in the database layer i would execute 2 update statements for each InvoiceItem in the collection.
Thanks for Helping
ajj3085 replied on Monday, June 12, 2006
qwerty123: The Invoiceitems and the ItemDetails tables are basically a one to one relationship and both have a InvoiceID and ItemID which are FK to Invoice and Items table. However the InvoiceItems has only the junction information and the rest of data is in the ItemDetails. Every record in InvoiceItems would have a record in ItemDetails (I KNOW I CAN COMBINE BOTH TABLES, HOWEVER THIS IS THE WAY I NEED IT NOW) so it's basically one object InvoiceItem but in the database it's split so do I need a new object for each table or I can combine into one, and in the database layer i would execute 2 update statements for each InvoiceItem in the collection.
It sounds like you're still building your business objects based on what the underlying tables look like. Your InvoiceItem class should hide the fact that they are in two seperate tables. I assume when you add a new item to your invoice, you'll do so by selecting a part number or other piece of information. So I'd think that the InvoiceItem would have some read only properties as well, such as description and perhaps price (it depends on what your business requirements are).
Just remember, that you DON'T create a business object to represent a table. Thats not what Csla is meant to support (or OO design, for that matter).
Andy
qwerty123 replied on Monday, June 12, 2006
Thanks I got it
Copyright (c) Marimer LLC