当前位置:网站首页>DEV XPO对比之UOW
DEV XPO对比之UOW
2022-07-01 05:51:00 【qq_16215957】
Producer XPObject:
using DevExpress.Data.Filtering;
//using DevExpress.Utils.Base;
using DevExpress.Xpo;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.BaseImpl.PermissionPolicy;
namespace XYZ.Module.BusinessObjects
{
//[ImageName("BO_Contact")]
//[DefaultProperty("DisplayMemberNameForLookupEditorsOfThisType")]
//[DefaultListViewOptions(MasterDetailMode.ListViewOnly, false, NewItemRowPosition.None)]
//[Persistent("DatabaseTableName")]
// Specify more UI options using a declarative approach (https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument112701).
public class XYZ_Producer : BaseObject
{ // Inherit from a different class to provide a custom primary key, concurrency and deletion behavior, etc. (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument113146.aspx).
// Use CodeRush to create XPO classes and properties with a few keystrokes.
// https://docs.devexpress.com/CodeRushForRoslyn/118557
public XYZ_Producer(Session session)
: base(session)
{
}
PermissionPolicyUser GetCurrentUser()
{
PermissionPolicyUser user = null;
try
{
//return Session.GetObjectByKey<PermissionPolicyUser>(SecuritySystem.CurrentUserId); // In XAF apps for versions older than v20.1.7.
user = Session.FindObject<PermissionPolicyUser>(CriteriaOperator.Parse("Oid=CurrentUserId()"));
}
catch (Exception ex)
{
}
return user; // In non-XAF apps where SecuritySystem.Instance is unavailable (v20.1.7+).
}
public override void AfterConstruction()
{
base.AfterConstruction();
CreatedOn = DateTime.Now;
CreatedBy = GetCurrentUser();
}
protected override void OnSaving()
{
base.OnSaving();
UpdatedOn = DateTime.Now;
UpdatedBy = GetCurrentUser();
}
//private string _PersistentProperty;
//[XafDisplayName("My display name"), ToolTip("My hint message")]
//[ModelDefault("EditMask", "(000)-00"), Index(0), VisibleInListView(false)]
//[Persistent("DatabaseColumnName"), RuleRequiredField(DefaultContexts.Save)]
//public string PersistentProperty {
// get { return _PersistentProperty; }
// set { SetPropertyValue(nameof(PersistentProperty), ref _PersistentProperty, value); }
//}
//[Action(Caption = "My UI Action", ConfirmationMessage = "Are you sure?", ImageName = "Attention", AutoCommit = true)]
//public void ActionMethod() {
// // Trigger a custom business logic for the current record in the UI (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112619.aspx).
// this.PersistentProperty = "Paid";
//}
string fCode;
[Size(255)]
//[XafDisplayName("编码")]
public string Code
{
get { return fCode; }
set { SetPropertyValue<string>(nameof(Code), ref fCode, value); }
}
string fName;
[Size(255)]
//[XafDisplayName("名称")]
public string Name
{
get { return fName; }
set { SetPropertyValue<string>(nameof(Name), ref fName, value); }
}
string fAddress;
[Size(255)]
//[XafDisplayName("名称")]
public string Address
{
get { return fAddress; }
set { SetPropertyValue<string>(nameof(Address), ref fAddress, value); }
}
string fLegalRepresentative;
[Size(255)]
//[XafDisplayName("负责人")]
//[ModelDefault("AllowEdit", "True")]
public string LegalRepresentative
{
get { return fLegalRepresentative; }
set { SetPropertyValue<string>(nameof(LegalRepresentative), ref fLegalRepresentative, value); }
}
string fContact;
[Size(255)]
//[XafDisplayName("负责人")]
//[ModelDefault("AllowEdit", "True")]
public string Contact
{
get { return fContact; }
set { SetPropertyValue<string>(nameof(Contact), ref fContact, value); }
}
private string _Phone;
//[XafDisplayName("电话")]
public string Phone
{
get
{
return _Phone;
}
set
{
SetPropertyValue("Phone", ref _Phone, value);
}
}
string fRemark;
[Size(255)]
//[XafDisplayName("备注")]
public string Remark
{
get { return fRemark; }
set { SetPropertyValue<string>(nameof(Remark), ref fRemark, value); }
}
PermissionPolicyUser createdBy;
//[ModelDefault("AllowEdit", "False")]
public PermissionPolicyUser CreatedBy
{
get { return createdBy; }
set { SetPropertyValue("CreatedBy", ref createdBy, value); }
}
DateTime createdOn;
//[ModelDefault("AllowEdit", "False"), ModelDefault("DisplayFormat", "G")]
public DateTime CreatedOn
{
get { return createdOn; }
set { SetPropertyValue("CreatedOn", ref createdOn, value); }
}
PermissionPolicyUser updatedBy;
//[ModelDefault("AllowEdit", "False")]
public PermissionPolicyUser UpdatedBy
{
get { return updatedBy; }
set { SetPropertyValue("UpdatedBy", ref updatedBy, value); }
}
DateTime updatedOn;
//[ModelDefault("AllowEdit", "False"), ModelDefault("DisplayFormat", "G")]
public DateTime UpdatedOn
{
get { return updatedOn; }
set { SetPropertyValue("UpdatedOn", ref updatedOn, value); }
}
}
}调用:
string connectionString;
IDataLayer dataLayer = null;
UnitOfWork uow = null;
private void tESTUOWToolStripMenuItem_Click(object sender, EventArgs e)
{
KeepUOWConnect();
XYZ_Producer producer = new XYZ_Producer(uow);
producer.Name = "";
producer.Contact = "david";
producer.Save();
uow.CommitChanges();
}
public void KeepUOWConnect()
{
try
{
if (uow == null)
{
logHelper.InfoOnce($"数据库连接为空!");
if (connectionString == null)
connectionString = ConfigurationManager.ConnectionStrings["ConnectionString_XYZData"].ConnectionString;
if (dataLayer == null)
dataLayer = XpoDefault.GetDataLayer(connectionString, DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema);
logHelper.InfoOnce($"数据库已连接!");
uow = new UnitOfWork(dataLayer);
}
}
catch (Exception ex)
{
logHelper.ErrorOnce($"数据库连接失败!{Environment.NewLine}Error Message:{Environment.NewLine}{ex.Message}{Environment.NewLine}StackTrace:{Environment.NewLine}{ex.StackTrace}");
}
finally
{
}
}
/// <summary>
///
/// </summary>
public void ReleaseUOWConnect()
{
try
{
if (uow != null)
{
uow.Disconnect();
uow.Dispose();
if (dataLayer != null)
{
dataLayer.Dispose();
}
dataLayer = null;
uow = null;
}
}
catch (Exception ex)
{
logHelper.ErrorOnce($"释放数据库连接失败!{Environment.NewLine}Error Message:{Environment.NewLine}{ex.Message}{Environment.NewLine}StackTrace:{Environment.NewLine}{ex.StackTrace}");
}
finally
{
}
}边栏推荐
- Oracle create user + Role
- Oracle 序列+触发器
- 运行时候的导包搜索路径虽然pycharm中标红但不影响程序的执行
- A little assistant for teenagers' physiological health knowledge based on wechat applet (free source code + project introduction + operation introduction + operation screenshot + Thesis)
- 我从技术到产品经理的几点体会
- Xuanyi maintenance manual
- Educational administration management system (free source code)
- OpenGL ES: (3) EGL、EGL绘图的基本步骤、EGLSurface、ANativeWindow
- El tooltip in the table realizes line breaking display
- Seven major technical updates that developers should pay most attention to on build 2022
猜你喜欢
![[note] e-commerce order data analysis practice](/img/03/367756437be947b5b995d5f7f55236.png)
[note] e-commerce order data analysis practice

Boot + jsp University Community Management System (with source Download Link)

4GB大文件,如何实时远程传输和共享?

Primary application case of Excel DuPont analyzer

穿越派·派盘 + Mountain Duck = 数据本地管理

OpenGL es: (3) EGL, basic steps of EGL drawing, eglsurface, anativewindow

OpenGL es: (5) basic concepts of OpenGL, the process of OpenGL es generating pictures on the screen, and OpenGL pipeline

MySQL数据迁移遇到的一些错误

FPGA - 7系列 FPGA内部结构之Clocking -01- 时钟架构概述

Send you through the data cloud
随机推荐
MySQL数据迁移遇到的一些错误
Retention rate of SQL required questions
Data governance: data governance management (Part V)
win10、win11中Elan触摸板滚动方向反转、启动“双指点击打开右键菜单“、“双指滚动“
POL8901 LVDS转MIPI DSI 支持旋转图像处理芯片
Educational administration management system (free source code)
Seven major technical updates that developers should pay most attention to on build 2022
Brief description of activation function
Code shoe set - mt3149 · and - the data is not very strong. Violent pruning can deceive AC
FPGA - 7系列 FPGA内部结构之Clocking -01- 时钟架构概述
喊我们大学生个人云服务特供商
2022.6.30-----leetcode. one thousand one hundred and seventy-five
Enter an expression (expressed as a string) and find the value of this expression.
SystemVerilog学习-09-进程间同步、通信和虚方法
My experience from technology to product manager
Dear pie users, I want to confess to you!
First defined here occurs during QT compilation. Causes and Solutions
uniapp树形层级选择器
HCM 初学 ( 二 ) - 信息类型
Smartinstantiationawarebeanpostprocessor of the extension point series determines which construction method to execute - Chapter 432