Farseer.net Lightweight Open Source Framework v1.x Introduction: New Release Notes

Source: Internet
Author: User

Navigation

Catalog: Farseer.net Lightweight Open source Framework Catalog

Previous: No

Next: Farseer.net Lightweight open Source Framework v1.x Introduction: Database Configuration

Objective

The v1.x version has finally arrived. This version of the development began in March, took one months to complete the concept of version design, development. In the April, several kernel reconfiguration designs were carried out. In the May, large-scale bug fixes and code optimizations were carried out.

As of today (early June), known bugs have been fixed and have been applied in 2 of projects and are working well.

This article topic

1. New Queue management:

The new version changes the way the v0.x is used and entityframework the reference design for the model .

In the new version, the concept of the queue , that is, when we operate on the table, is not a one-sentence operation, often a logic inside the different tables will be repeated operations, and finally in the SaveChange () commit to the database. When SaveChange () is triggered, all queues (queue) are iterated through queue Management (Queuemanger) to commit to the database.

This involves the concept of deferred execution .

2. New Batch submission:

In the previous version,User. Data. Insert (new User{UserName = "NewName"}); will be executed immediately,

The new Table () mode is deferred to SaveChange () to SQL, SQL parameterized, and then submitted to the database , which is similar to EntityFramework.

Of course also provided with the old version of the operation, provided here is not for the sake of compatibility, but for sometimes we do not need to operate the table many times, it may just be a simple one to insert a new record.

The new version provides two ways

3. New database operation:

1 Table.Data.User.Insert (new"yy" });
1 using (varnew  Table ()) 2 {3     var New " xx "  }; 4     context. User.insert (info); 5     context. SaveChanges (); 6 }

Only the first method is available in the old version, and in the new version it is the second one.

In the second way, only in the context. SaveChanges () before the operation of the database takes effect. This is from the point of view of the invocation, of course, in the new version, the kernel processing mode completely changed.

The second is that entity class mappings are completely different and more lightweight. No longer relies on the base class provided by the framework (the old version is forced to inherit), and the new version cancels the base class of the entity class .

Mapping of new entity classes

4. Changed entity class:

1 [Context ()]2      Public classTable:tablecontext<table>3     {4[Set (Name ="Members_user")]5          PublicTableset<uservo> User {Get;Set; }6 7[Set (Name ="Members_role", Iscache =true)]8          PublicTableset<userrolevo> Userrole {Get;Set; }9     }Ten  One      Public classuservo:ientity<int?> A     { -         /// <summary> -         ///User ID the         /// </summary> -[Field (IsPrimaryKey =true)] -          Public int? ID {Get;Set; } -         /// <summary> +         ///User name -         /// </summary> + [Field ()] A          Public stringUserName {Get;Set; } at  -         /// <summary> -         ///Password -         /// </summary> -          Public stringPassWord {Get;Set; } -}

See the above Entity class mapping, is not feel very like entityframework DbContext, dbset it.

It is not necessary for Uservo to inherit ientity<int?>. After inheriting it, the framework provides some additional extended support. (later in the article in detail)

In the new version, the primary key int ID is not a mandatory inheritance , so it cannot be easily provided as in the previous version:User. Data. Toinfo (1). To achieve this effect, you must inherit this ientity interface.

Separation of PO and VO. In older versions, if you have more than one table with a field structure that is exactly the same, you must define the same entity class for each table when you map. This is a bloated code for the project.

In the new version, Vo is out of the frame, and the table is the one that determines the structure of "who" to map it, which gives us a very flexible way to encode our implementation projects, such as multiple database tables corresponding to the same VO entity.

The map mode of the entity class is separated.

5. Map separated:

In the old version, there was no separation because the entity class had only one. So the entire class is mapped and cached.

And in the new version, from the above we have seen that the separation. became three types: Table, Tableset, solid Vo.

So the corresponding map also has:contextmap(mapping Table properties,tableset characteristics),FieldMap(the field properties of the mapped entity VO)

They are in the namespace: FS.Mapping.Context

Here, everyone has a better understanding of the line. The actual project is not used much, but more is the internal call within the Fs.core. It marks the mapping of individual entity classes.

Now that the map has changed, the attribute tag for the entity class has changed.

    • Dbattribute No, replaced by:ContextAttribute.
    • Columnattribute No, replaced by:SetAttribute,fieldattribute
Unified Cache Management

6, unified the management of the cache:

In the original version, some of the cached (such as reflected, enumerated Chinese names, ORM) exist in their own management.

In the new version, the unification is put to fs.core. The Cachemanger . and provides the clear () method to clear all caches.

  

The specific code is not posted here, you can see the cache management from the place.

Separation of the new version structure

7, the separation of the structure:

The above is the change of the invocation mode and the entity class mapping. To make it easier to promote open source, the framework is also structurally separated:

  

    • farseer.net: ORM Mapping, Database operations.
    • Farseer.Net.Utils: Provides common tool classes (but no association with WinForm, WebForm, MVC)
    • Farseer.Net.Utils.Form: tools to provide WinForm
    • Farseer.Net.Utils.Web: Provides tools for WebForm, MVC

  

In a real-world project, you might not use a tool class other than ORM (Everyone has a tool class that you have already used). So that the ORM is more focused.

Therefore, this series of tutorials, only to explain the Farseer.net related code, other tool classes please do their own research after the cut. (In fact, there is nothing to research, just some tool-like method)

The difference between the two versions is huge, and the author is completely rewritten in the new version, so the differences between the old and the new versions cannot be described in this article. This article is only to give you a preliminary impression, after the space, we will explain each application.

Example of a call

8, the new encoding method:

Finally, we are pasting an example of a synthetic call to everyone:

1 using(varContext =NewTable ())2 {3     varInfo = context. User.where (o = o.id >0&& O.createat < DateTime.Now). Desc (o =New{o.id, o.logincount}). ASC (o =o.gendertype). Toentity ();4Info. PassWord ="77777";5Context. User.where (o = o.id = =1). Update (info);6 7Info.id =NULL;8Info. PassWord ="00000New";9 context. User.insert (info);Ten  One  AContext. User.where (o = o.id = =1). Append (o = O.logincount,1). Addup (); -Context. User.addup (o = O.logincount,1); - context. Userrole.tolist (); theContext. Userrole.where (o = o.id = =1). ToList (); -Context. Userrole.where (o = o.id >1). ToList (); -     varLST = context. User.where (o = o.id >0). Desc (o =New{o.id, o.logincount}). ASC (o =o.gendertype). ToList (); -  + context. SaveChanges (); -}
1 New 0 ). ToList (); 2 1 ); 3 0 ). ToList (); 4 0). ToList ();

This article does not speak much of the substantive code, mainly to explain the new and old version of the contrast, so that everyone has an intuitive impression.

This is explained in this article, and the rest of the space will begin to really lead you to the new frame of attraction.

Navigation

Catalog: Farseer.net Lightweight Open source Framework Catalog

Previous: No

Next: Farseer.net Lightweight open Source Framework v1.x Introduction: Database Configuration

Advertising time

QQ Group:116228666 (farseer.net Open source frame exchange) Please specify:farseer.net

Farseer.net is an ORM framework + Common tool + extension collection.

Farseer implication: Prophets and seers usually offer tricks and strategies in certain situations. Also hope that the framework can provide you with maximum convenience.

ORM: The English name is:object relational(relationship) Mapping(map)

Farseer.net's goal is: Quick start, rapid development, simple and convenient.

1Table.data.User. Where (O=>o.id = =1). toentity ();2Table.data.User. Where (O=>o.id >1). ToList ();3Table.data.User. Where (o=>o.id! =0). Delete ();4Table.data.User. Where (o=>o.id! =0).Addup(O=>o.logincount,1);5Table.data.User. Where (O=>o.id = =1).Update(Newuser{UserName ="NewName" });6Table.data.User.Insert(Newuser{UserName ="NewName"});

Farseer.net Lightweight Open Source Framework v1.x Introduction: New Release Notes

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.