随笔 - 2  文章 - 4 评论 - 1 trackbacks - 1

eXpress Persistent Objects can perform semi-automatic change tracking using the Unit of Work principle. Unit of Work maintains a list of persistent objects that are affected by a transaction. It keeps track of every change to every persistent object during a transaction that can affect a data store. With a single call to the UnitOfWork.CommitChanges method, all the changes made to the persistent objects are automatically saved to a data store. When working with common sessions, you need to save each persistent object individually.

Unit of Work is represented by a UnitOfWork or ExplicitUnitOfWork class. These classes inherit the base functionality from the Session class and provide the UnitOfWork.CommitChanges method that is used to save all changed persistent objects to a data store. The only requirement for this is that the property setters call the XPBaseObject.OnChanged method. To simplify things, you can call the SetPropertyValue method to meet the requirement, as shown below.

Declaring a Persistent Object

 

public class UOWPerson : XPObject
{
    string fName;
    public UOWPerson(Session session) : base(session) { }
    public UOWPerson(Session session, string name) : base(session)
    {
        this.fName = name;
    }
    public string Location { 
        get { return GetPropertyValue<string>("Location"); }
        set { SetPropertyValue<string>("Location", value); }
    }
    public string Name {
        // We cannot use GetPropertyValue in the getter  
        // below because the fName field is explicitly defined 
        get { return fName; }
        set { SetPropertyValue<string>("Name", ref fName, value); }
    }
}
NoteNote

SetPropertyValue automatically calls the XPBaseObject.OnChanged method to track changes made to the Name and Location properties. Once Unit of Work's UnitOfWork.CommitChanges method is called, the changes will be automatically saved to a data store. You should always implement properties this way, if you wish changes to be recognized automatically in Units of Work.

 

Using Units of Work in XPO

The following sample creates a new instance of the UnitOfWork class (uow object) with default settings. In this case, there is no specific rollback code and the changes are only committed to the database if the UnitOfWork.CommitChanges method is executed. The UnitOfWork class derives from Session and thus all objects that are being handled within a unit must be fetched via that unit or associated with it by means of the session constructors in the XPO base classes.

using(UnitOfWork uow = new UnitOfWork()) {
    // Create, update or delete objects 
    uow.CommitChanges();
}

After this we create three persistent objects of the UOWPerson type that has been declared above. If the Session has been used, then we save each persistent object individually by calling its XPBaseObject.Save method. While using Unit of Work, only one UnitOfWork.CommitChanges method call is needed to save all the made changes.

using(UnitOfWork uow = new UnitOfWork()) {
    UOWPerson p = new UOWPerson(uow, "Mike");
    // p.Save(); when working with a Session 

    p = new UOWPerson(uow, "John");
    // p.Save(); when working with a Session 

    p = new UOWPerson(uow);
    p.Name = "Bob";
    p.Location = "US";
    // p.Save(); when working with a Session 

    // Save all the changes made 
    uow.CommitChanges();
}

Internally, the UnitOfWork class uses a single transaction that is started automatically, committed in the UnitOfWork.CommitChanges method, and rolled back when the unit is being disposed.

 

 

posted @ 2011-10-15 22:11 随心飞翔 阅读(30) 评论(0) 编辑

摘自〈中国康网  〉http://www.kwkj.cn/forums/blogs/zqf/archive/2006/09/15/13692.aspx
1
拷贝文件

(1)CuteEditorBin文件夹下的:

CuteEditor.dll

CuteEditor.lic(解密文件)

CuteEditor.ImageEditor.dll 5.0增加的EditorImage功能)

NetSpell.SpellChecker.dll(拼写检查功能)

拷贝到项目的Bin目录下。

注:.dic为扩展名的文件是词典保存为纯文本文件的格式。将bin文件夹里的都拷到项目的bin目录下也可以)

(2)CuteSoft_Client文件夹及文件拷贝到项目的相应目录。

:FilesPath用来设置所对就的目录,如:

FilesPath="~/admin/CuteSoft_Client/CuteEditor/"

(3)example.css文件拷贝到相应目录,并设置EditorWysiwygModeCss属性。如:EditorWysiwygModeCss="/admin/CuteSoft_Client/CuteEditor/themes/example.css

综合设置如下:

<CE:Editor ID="Editor1" runat="server" FilesPath="~/admin/CuteSoft_Client/CuteEditor/" EditorWysiwygModeCss="/admin/CuteSoft_Client/CuteEditor/themes/example.css">        </CE:Editor>

2、修改Web.config文件

  <appSettings>

     <add key="DictionaryFolder" value="bin" />

  </appSettings>

  <system.web>//注本节代码在.net2.0下是否需要设置,本人未验证。

     <browserCaps>

       tagwriter=System.Web.UI.HtmlTextWriter

     </browserCaps>

  </system.web>

3、引用:

·<%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>

·<CE:Editor ID="ce1" runat="server" FilesPath="~/admin/CuteSoft_Client/CuteEditor/" EditorWysiwygModeCss="~/Admin/CuteSoft_Client/CuteEditor/Themes/example.css" ThemeType="Office2003_BlueTheme" >

</CE:Editor>

注:

可修改CuteSoft_Client\CuteEditor\Configuration\AutoConfigure文件夹下的文件,改便CuteEditor工具栏按钮的显示或排列。

可修改文件CuteSoft_Client\CuteEditor\Configuration\Shared\Common.config来添加字体。

本文部分内容参考自互联网   qq:179085614

posted @ 2006-09-15 17:12 随心飞翔 阅读(980) 评论(1) 编辑