Preliminary understanding of rapid development of ~RAFY framework

Source: Internet
Author: User

when we started to use EF at the same time, is not a better understanding of the other ORM framework, recently contacted the use of Rafy, the feeling is still very interested to learn, although the original I do not see the depth of the present, but I personally feel can simply do some summary of, perhaps not much language, But more want to summarize the use of it, no contact with the friends can also be simple to know, hey.

If you want to use the RAFY framework, it's really simple, just open vs and then select Extensions and updates in the toolbar and then search for RAFY.SDK installation.

Simple use of the Rafy framework

Speaking of using, in fact, is very simple to get started, when we set up our solution we will create a new project of their own, we add the project will find the following options:

You can then select the Rafy framework to create the project, and look at the creation of the entity class as follows:

The content of the Dbiplugin class is actually the name of a database set :

dbientity class:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Runtime.Serialization;usingSystem.Security.Permissions;usingSystem.Text;usingRafy;usingRafy.componentmodel;usingRafy.domain;usingRafy.Domain.ORM;usingRafy.Domain.Validation;usingRafy.metamodel;usingRafy.MetaModel.Attributes;usingRafy.MetaModel.View;usingRafy.managedproperty;namespacedbi{[Serializable] Public Abstract classdbientity:longentity {#regionconstructor functionprotecteddbientity () {} [SecurityPermissionAttribute (SecurityAction.Demand, SerializationFormatter=true)]        protectedDbientity (SerializationInfo info, StreamingContext context):Base(info, context) {}#endregion} [Serializable] Public Abstract classdbientitylist:entitylist {} Public Abstract classDbientityrepository:entityrepository {protecteddbientityrepository () {}} [Dataproviderfor (typeof(dbientityrepository))]  Public classDbientityrepositorydataprovider:rdbdataprovider {protected Override stringConnectionstringsettingname {Get{returnDbiplugin.dbsettingname;} }    }     Public Abstract classDbientityconfig<tentity>: entityconfig<tentity> { }}

that 's dbientity. This class, in fact, is a base class of an entity class, for example, we create an entity class user, right click Add Select the first can, as follows:

Then there is a choice for this class:

In General, we choose to build the warehouse at the same time, of course, we can just add the entity, and then choose to add the warehouse can also, hey, look at the user entity class:

/// <summary>    ///User/// </summary>[Rootentity, Serializable] Public Partial classuser:dbientity {#regionconstructor function PublicUser () {} [SecurityPermissionAttribute (SecurityAction.Demand, SerializationFormatter=true)]        protectedUser (SerializationInfo info, StreamingContext context):Base(info, context) {}#endregion        #regionReference properties#endregion        #regionCombining Sub-Properties Public Static ReadOnlylistproperty<userchildlist> userchildlistproperty = P<user>. Registerlist (E =e.userchildlist);  Publicuserchildlist userchildlist {Get{return  This. Getlazylist (Userchildlistproperty); }        }         Public Static ReadOnlylistproperty<permissionlist> permissionlistproperty = P<user>. Registerlist (E =e.permissionlist);  Publicpermissionlist permissionlist {Get{return  This. Getlazylist (Permissionlistproperty); }        }        #endregion        #regionGeneral properties Public Static ReadOnlyproperty<string> NameProperty = p<user>. Register (E =e.name); /// <summary>        ///name/// </summary>         Public stringName {Get{return  This. GetProperty (NameProperty); }            Set{ This. SetProperty (nameproperty, value); }        }         Public Static ReadOnlyproperty<int> Ageproperty = p<user>. Register (E =e.age); /// <summary>        ///Age/// </summary>         Public intAge {Get{return  This. GetProperty (Ageproperty); }            Set{ This. SetProperty (ageproperty, value); }        }        #endregion        #regionRead-only properties#endregion    }    /// <summary>    ///user List class. /// </summary>[Serializable] Public Partial classuserlist:dbientitylist {}/// <summary>    ///user Warehouse class. ///responsible for the user class query, save. /// </summary>     Public Partial classUserrepository:dbientityrepository {/// <summary>        ///Singleton mode, the outside world can not directly construct this object. /// </summary>        protecteduserrepository () {} [Repositoryquery] Public VirtualUserList Getbyname (stringname,paginginfo Paginginfo) {            varQ = This.            Createlinqquery (); Q= Q.where (E = E.name = =name); return(userlist) This.        Querydata (q, Paginginfo); } [Repositoryquery] Public VirtualEntitylist Getbysql (stringname,paginginfo Paginginf) {Formattedsql SQL=@"SELECT * FROM [dbo]. [User] WHERE a.name ={0}"; Sql.            Parameters.Add (name); return(userlist) ( This. Dataqueryer asrdbdataqueryer).        Querydata (SQL); }    }    /// <summary>    ///The User Configuration class. ///The configuration of the entity metadata that is responsible for the user class. /// </summary>    Internal classUserconfig:dbientityconfig<user>    {        /// <summary>        ///to configure metadata for an entity/// </summary>        protected Override voidConfigmeta () {//All properties of the configuration entity are mapped to the data table. meta.maptable ().        Mapallproperties (); }    }}

in fact, the addition has been set up a lot of their own code snippets, in the addition of properties is also a lot of convenience, the following simple to write a common attribute added shortcut keys, as follows:

Rafyproperty+tab Key: The addition of general attributes;

Rafypropertyextension+tab Key: The addition of extended attributes;

Rafypropertyreadonly+tab Key: The addition of read-only attributes;

Rafypropertyreference+tab Key: The addition of reference attributes;

Rafypropertyreferencenullable+tab Key: The addition of a nullable reference attribute;

I can only write a simple to write a common, hey.

Once the entity class has been added above, We can see the file domainmodel1.odml, in fact, he is the entity of the relationship diagram, with it our entity's attribute relationship has been the relationship between the class is more clear, the following simple to add the way, like the above right click to select Add, will appear the following page, choose to add:

enter into the file as follows, select Add Entity class, the left is when the entity class has been updated, you can refresh the entity class, click the Add Entity Class button and then appear as shown, select the rendered entity class, we can all choose also can.

when we select the following diagram as follows:

I simply add a few entity classes here, hehe, in order to show the diagram of the Odml class file.

Here is a simple summary of the Rafy of the simple use, the next may be written a small demo.

Preliminary understanding of rapid development of ~RAFY framework

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.