This is a migrated thread and some comments may be shown as answers.

Business Objects

4 Answers 75 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sebastian
Top achievements
Rank 1
Sebastian asked on 01 Nov 2012, 03:24 PM
Hello,

Let's say I have the following tables:

OrderHead, OrderDetails, Customer, and ShipTo. I can create Domain Model for each table, but how would I go about creating a "Business Object" name "Sales Orders" that contains information from all four tables?


Thanks

4 Answers, 1 is accepted

Sort by
0
Sebastian
Top achievements
Rank 1
answered on 02 Nov 2012, 08:09 PM
I think I figured it out. Each table will be it's own object. I would then have to create another object named "Sales Order" that would contain a collection of objects...namely OrderDetails, Customer, and ShipTo.
0
Doroteya
Telerik team
answered on 05 Nov 2012, 03:15 PM
Hi Sebastian,

A good approach regarding the business objects is to create either a view or a stored procedure for each one of them in the database, map them in the domain model and use them to retrieve the necessary data.

If you choose to work with a view, note that although Telerik OpenAccess ORM maps it as a class in the model, it cannot retrieve information from the database about its primary key. In that case, you will have to set up the domain model in one of the ways described in this article.

If you choose to work with a stored procedure, you need to add it in the model and set it up with the Domain Method editor. There you will have to specify the type of the returned result as described in this article.

Note that I assume that when you say Domain Model in your first post, you mean Domain Class. I also assume that you use an existing database and apply Database first approach.

If any of my assumptions are wrong or you experience problems with the options I suggested, do not hesitate to get back to us.


Regards,
Doroteya
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
0
Sebastian
Top achievements
Rank 1
answered on 05 Nov 2012, 06:15 PM
Your first assumption is correct....I did mean Domain Class. I'm using model first approach.

If I go about using Stored Procedures I would have to create "business functions" (e.g. adding,removing,modifying) SalesOrder in one stored procedure...correct? Or could I use LINQ for CURD operations against domain model/class?

In regards to business objects I found an example here (stackoverflow.com) on objects and collections. In a nutshell:

public class Incident { ... }
public class Person { ... }
public class Comment { ... }

public class IncidentPersonal { List<Person> p; .... }
public class PersonnelNotes { List<Note> n; ... }

At the end of the answered post the author states " You can use an ORM or write up your own DAL". I'm guessing this where I choose one of the approaches you had mentioned in your response. Or would this approach not work well?

This is my first attempt with OpenAccess. I have used EF (Entity Framework) before. With LazyLoading enabled I was able to "drill down" to related domain classes using LINQ to Entities and add/modify data in related class models.

I should have asked this question from the get go....Am I going about this the wrong way? Should I even worry about Business Objects? I could just as well create 4 context, one for each class.


Thanks
0
Doroteya
Telerik team
answered on 07 Nov 2012, 12:36 PM
Hello Sebastian,

To get a good overview of some fundamental Telerik OpenAccess ORM features an capabilities, I suggest you the following documentation articles and videos:
    - What is OpenAccess and how do you benefit from it? - here
    - How to implement the Model First scenario? - articlevideo
    - How to create relationships between the classes in the model? - here
    - What is Round Trip scenario? - here
    - What is the OpenAccessContext? - here
    - How to execute CRUD operations? - here
    - Does OpenAccess support LINQ? - here
    - How to map CUD operations to stored procedures? - article, video

My suggestion about the steps to implement your idea is as follows:
1) Start to create the domain model using the Model First scenario
   - Add classes in the model - you can drag the Domain Class item from the toolbox and drop it on the Visual Designer surface.

You will notice that the class is separated to three parts: properties, implementation and navigation. The first part contains those properties that correspond to the columns in the table to which the class is mapped. The second part consists of implementation properties. This type of properties is generated by OpenAccess when you implement some kind of inheritance. And the last part of the class is the navigational properties. They are created when you build the relationships between your classes.

For example: The classes Incident and Person are connected with 1 to Many association but Incident is not a parent of Person. So the structure of Incident will be: in properties you will have the scalar properties of the class, the implementation section will be empty and in the navigation section you will find a property of type IList<Person>, that will contain a list of all the persons connected to a given incident.

   - Make the necessary settings for the class' properties (data types, primary keys and etc.)
   - Create relationships between them (OpenAccess will generate the necessary navigation properties)

2) Map the classes to tables - you can use either default or explicit mapping
3) Generate CUD operations for the classes that need them
4) Migrate your model to the database
5) For other changes of the model use the steps described in the Round Trip scenario

Once your model is done you can execute CRUD operations using the generated context.

If you have additional questions or need help with the solution I provided, do not hesitate to get back to us.

Greetings,
Doroteya
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
Tags
Data Access Free Edition
Asked by
Sebastian
Top achievements
Rank 1
Answers by
Sebastian
Top achievements
Rank 1
Doroteya
Telerik team
Share this question
or