c# - Should one extend or encapsulate ORM objects? -


I have a problem understanding the use of ORM created objects. We are using LLBLGen for mapping our database model objects.

It might be better to code this code.

  Our application as public class book {// Class used in the Private BookEntity book; // LLBLGen unit Private BookType bookType; // BookType is another class that wraps an entity's public book {ENT EID} {book = new BookEntity (ID); } Public BookType BookType {get {return.bookType; } Set {this.bookType = value; This.book.BookType = New BookTypeEntity (value.ID); This.book.Save (); }} Public Integer Calculation Page () {} Business Method of Example}  

It is strange to highlight the areas of the institution such as properties, because I am mapping again list-types With this it is very bad, because I have to write an "add" and "remove" method and a property that displays the property.

In the above example, I need access to the BookType Setter BookTypeEntity object, I can get this object by using a new object using the BookType Object ID I also do not feel good.

I am thinking that I should not extend booky objects and add my business logic there? Or perhaps partial use?

In the example of LLGL, they use unit objects directly, but it looks very messy to me. I want to do those objects in the above code, in my business logic (like count pages). May be in ways also.

If possible in the LLGL gene, but if I work with ORM, then I generally But I want to create an interface to my current version, IBook in your example. I expose this interface through a public singer from the wrapping class. In this way, if you need to, you want to add some custom behavior to your desired area, you can increase it as much as you want.

Generally, I think there are 3 ways to "mapping" your ORM - Specification in your domain:

  1. Basically, the way you post,
  2. Expose the ORM-entity as the interface
  3. Expose the ORM unit directly

I do not like # 1, because I do not like 2 mapping in my application. Dry, kissing and all of the yagnas are a violation of it.

I do not like # 3 because it will make any consumer layer of your domain layer directly on the ORM layer.

.. So, I go with # 2, because it is less than 3 evils;)

[Update] Short code snippet :)

ORM-Generated class data-layer:

  Public class book: Ibec {public string ISBN {get; Private set;}} IBook is found in the trade logic level with a scroll cover:  
  public interface IBook {string ISBN {get; }} Public Classroom BookWrapper // or whatever you want to call it :) {// Create a new book in Constructor BookWrapper () {BookData = New Data.MyORM.CreateNewBook ​​(); } // Expose IBK, so we do not have to cascade ISBN calls to public IB book bookata {get; Protected set;} // Any business logic operation required here, public author Lookup at (here) (if (Ikk == empty) throw the new system expression ("No, the rings of this book do not have IBQ :( ") // Contact ISKN}}  

To search the book's author, some websites, I do not know that this is an identifiable design-pattern, but it's used I am, and by now it is quite Has worked Chci :)


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -