Farseer.net Lightweight Open Source Framework primer: Selection of logical layers

Source: Internet
Author: User

Navigation

Catalog: Farseer.net Lightweight Open source Framework Catalog

Previous: Farseer.net lightweight Open source Framework primer: Introduction: Add, delete, change, check operation demo

Next: Farseer.net Lightweight open source framework Getting started: entity classes

Once we have created an entity class, we need to inherit one of the base classes: Basemodel, Basecachemodel, Basecatemodel. The framework can establish a database relational mapping (that is, ORM) to entities only if one of these three base classes is inherited. And the curd operation of the database is implemented.

This framework differs from some other frameworks in that a series of operations such as INSERT, Update, Delete, ToList, Toinfo, and so on, do not require the build tool to generate these methods. Because we used the. NET great generics for encapsulation.

Basemodel: normal Logic Layer
 Public class users:basemodel<users>{}

After inheriting the Basemodel, the following properties are inherited

1         /// <summary>2         ///Query Results3         /// </summary>4          Public StaticDataresult<tinfo> Dataresult {Get;Set; }5 6         /// <summary>7         ///Persistence of Databases8         /// </summary>9          Public StaticBean<tinfo>DataTen         { One             Get A             { -                 varBean =NewBean<tinfo>(); -Dataresult =Bean. Dataresult; the                 returnBean; -             } -         } -  +         /// <summary> -         ///Persistence of Databases +         /// </summary> A          Public StaticCachedatabean<tinfo>Cache at         { -             Get -             { -                 varBean =NewCachedatabean<tinfo>(); -Dataresult =Bean. Dataresult; -                 returnBean; in             } -}

Users.dataresult: Returns the query that executes the database, such as execution time, SQL statement execution.

Users.data: Is the curd operation on the database. (In Basemodel, all the additions and deletions are here) it returns a Bean<user> object. In this object. You can perform any curd operations on the database.

Users.cache: Cache operation. This cache is not the same as the principle of the caching logic layer, and the purpose is not the same. (Specify in the normal logic layer: point here) here only need to know, it is based on the execution of SQL, hit cache.

Basecachemodel: Caching the logical layer
 Public class users:basecachemodel<users>{}

After inheriting the Basecachemodel, the following properties are inherited

1         /// <summary>2         ///Query Results3         /// </summary>4          Public StaticDataresult<tinfo> Dataresult {Get;Set; }5 6         /// <summary>7         ///Persistence of Databases8         /// </summary>9          Public StaticCachebean<tinfo>DataTen         { One             Get A             { -                 varBean =NewCachebean<tinfo>(); -Dataresult =Bean. Dataresult; the                 returnBean; -             } -         } -  +         /// <summary> -         ///Data Cache Operations +         /// </summary> A         /// <param name= "db" >Transactions</param> at          Public StaticList<tinfo> Cache (Dbexecutor db =NULL) -         { -             returndata.tolist (db); -}

The caching logic layer is a one-time cache of the entire table's data without any conditions. Once an operation is generated with the table, it is first judged whether it is cached locally.

Specifically, when manipulating the data of this table (that is, the operation of the Database property). ) updates the local cache and database data at the same time, which can be easily understood as "synchronous" updates.

The Users.cache () here is the method. And the normal logical layer is the attribute. Note the difference. The object returned here is List<users>, and the subsequent operation is not necessary for me to teach it. is the local variable query.

The object returned by the users.data here has changed. It's:cachebean<tinfo>. This includes only updates to the database: new, deleted, modified. The query operation is in Users.cache ().

Basecatemodel: Classification logic layer (with cache)
 Public class users:basecatemodel<users>{}

After inheriting the Basecatemodel, the following properties are inherited

1         /// <summary>2         ///Query Results3         /// </summary>4          Public StaticDataresult<tinfo> Dataresult {Get;Set; }5 6         /// <summary>7         ///Persistence of Databases8         /// </summary>9          Public StaticCachebean<tinfo>DataTen         { One             Get A             { -                 varBean =NewCachebean<tinfo>(); -Dataresult =Bean. Dataresult; the                 returnBean; -             } -         } -  +         /// <summary> -         ///Data Cache Operations +         /// </summary> A         /// <param name= "db" >Transactions</param> at          Public StaticList<tinfo> Cache (Dbexecutor db =NULL) -         { -             returndata.tolist (db); -}

Classification logic layer, mainly used in some need to support the infinite recursive tree data. The Tree of me is: must have a root node, the root node has unlimited child nodes, there is no node limit. For example, we used to have: (Channel, XXX category)

This is exactly the same as the Basecachemodel operation. The only difference is that Basecatemodel is inherited from Modelcateinfo. This class provides the default number of fields:

1     /// <summary>2     ///Classification base class3     /// </summary>4      Public classModelcateinfo:modelinfo5     {6         /// <summary>7         ///Owning ID8         /// </summary>9[Display (Name ="category of Belong")]Ten          Public Virtual int? ParentID {Get;Set; } One  A         /// <summary> -         ///title -         /// </summary> the[Display (Name ="title"), Stringlength ( -), Required] -          Public Virtual stringCaption {Get;Set; } -  -         /// <summary> +         ///Sort -         /// </summary> +[Display (Name ="Sort")] A          Public Virtual int? Sort {Get;Set; } at}

Also, you need to do more with the extension method. (Namespace for extension methods: using FS.) Extend)

The extension method provides a series of search methods for the subordinate nodes. such as querying the parent, top-level, subordinate, and so on. Of course there are a lot of methods inside. Specific people in: FS.Extend.ListExtend class to view.

Summarize

Three logical layers simply introduced here, I believe you can use the entity class, you know how to choose which logic layer to use.

With large data volumes and high update frequencies, it is recommended to use only Basemodel, the normal logic layer

It is recommended to use Basecachemodel as the cache logic layer when the data volume is small and the update frequency is low.

For data with small data volumes, less frequent updates, and recursive tree node types, it is recommended to use Basecatemodel as the cache logic layer

Navigation

Catalog: Farseer.net Lightweight Open source Framework Catalog

Previous: Farseer.net lightweight Open source Framework primer: Introduction: Add, delete, change, check operation demo

Next: Farseer.net Lightweight open source framework Getting started: entity classes

Farseer.net Lightweight Open Source Framework primer: Selection of logical layers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.