本文整理汇总了C#中UnitOfWork.CommitChanges方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.CommitChanges方法的具体用法?C# UnitOfWork.CommitChanges怎么用?C# UnitOfWork.CommitChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.CommitChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public override void Update() {
var unitOfWork = new UnitOfWork(Session.DataLayer);
if (unitOfWork.FindObject<PersistentAssemblyInfo>(null) != null)
return;
var persistentAssemblyInfo = new PersistentAssemblyInfo(unitOfWork){Name = "TestAssembly"};
var persistentClassInfo = new PersistentClassInfo(unitOfWork){
PersistentAssemblyInfo = persistentAssemblyInfo
};
persistentAssemblyInfo.PersistentClassInfos.Add(persistentClassInfo);
persistentClassInfo.SetDefaultTemplate(TemplateType.Class);
persistentClassInfo.Name = "TestClassInfo";
persistentClassInfo.BaseType = typeof (Customer);
persistentClassInfo.MergedObjectType = typeof (Customer);
persistentClassInfo.TypeAttributes.Add(new PersistentDefaultClassOptionsAttribute(unitOfWork));
persistentClassInfo.TypeAttributes.Add(new PersistentMapInheritanceAttribute(unitOfWork){
MapInheritanceType = MapInheritanceType.ParentTable
});
var persistentCoreTypeMemberInfo = new PersistentCoreTypeMemberInfo(unitOfWork){
DataType = DBColumnType.String,
Name = "TestProp"
};
persistentClassInfo.OwnMembers.Add(persistentCoreTypeMemberInfo);
persistentCoreTypeMemberInfo.SetDefaultTemplate(TemplateType.ReadWriteMember);
unitOfWork.CommitChanges();
}
示例2: btnProdRouteAdjustQty_Execute
private void btnProdRouteAdjustQty_Execute(object sender, SimpleActionExecuteEventArgs e)
{
if (View.CurrentObject == null)
return;
ProdRoute prodRoute = (ProdRoute)View.CurrentObject;
float adjustQty = 0;
try
{
adjustQty = float.Parse(
Microsoft.VisualBasic.Interaction.InputBox(string.Format("请输入要调整的数量, 现时最多可调整的数量为{0}\n输入0则取消调整", prodRoute.WipQty + prodRoute.TotalAdjustQty), "调整的数量", "0", 0, 0));
if (adjustQty > prodRoute.WipQty + prodRoute.TotalAdjustQty)
{
XtraMessageBox.Show("输入调整数量大于可调整数 !!");
return;
}
}
catch
{
XtraMessageBox.Show("输入数量错误 !!");
return;
}
UnitOfWork uow = new UnitOfWork();
uow.BeginTransaction();
ProdRoute pRoute = uow.GetObjectByKey<ProdRoute>(prodRoute.Oid);
pRoute.TotalAdjustQty = adjustQty;
pRoute.UpdateTotalIOQty();
pRoute.Save();
uow.CommitChanges();
View.ObjectSpace.Refresh();
}
示例3: RegisterButton_Click
protected void RegisterButton_Click(object sender, EventArgs e)
{
using (var uow = new UnitOfWork())
{
Customer customer = new Customer(uow);
customer.FirstName = FirstNameTextBox.Text;
customer.LastName = LastNameTextBox.Text;
customer.EmailAddress = EmailAddressTextBox.Text;
customer.Password = PasswordTextBox.Text;
customer.VerifyPassword = VerifyPasswordTextBox.Text;
ValidationResult validation = new CustomerForRegistrationValidator().Validate(customer);
if (validation.IsValid)
{
uow.CommitChanges();
HttpSession session = HttpSession.CurrentSession();
session.ActiveCustomer= customer;
session.SaveSession();
session.SetClientCookie();
Response.Redirect(HttpSession.CurrentSession().LoginRedirectUrl);
}
else
{
foreach (var error in validation.Errors)
{
var control = (DevExpress.Web.ASPxTextBox)RegisterFormLayout.FindControl(String.Format("{0}TextBox", error.PropertyName));
ShowValidationErrorForControl(control, error.ErrorMessage);
}
}
}
}
示例4: PhonebooksGridView_RowInserting
protected void PhonebooksGridView_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
{
ASPxGridView grid = sender as ASPxGridView;
if (CustomerUtilities.IsLoggedIn() == true)
{
using (var uow = new UnitOfWork())
{
Phonebook phonebook = new Phonebook(uow);
SetPhonebookValues(phonebook, e.NewValues);
phonebook.Customer = uow.GetObjectByKey<Customer>(CustomerUtilities.CurrentCustomer().Oid);
ValidationResult validation = new PhonebookValidator().Validate(phonebook);
if (validation.IsValid)
{
uow.CommitChanges();
}
else
{
e.Cancel = true;
uow.Dispose();
}
}
}
else
{
Response.Redirect(UrlManager.Root);
}
EndEditing(grid, e);
}
示例5: UpdateDatabaseBeforeUpdateSchema
public override void UpdateDatabaseBeforeUpdateSchema() {
base.UpdateDatabaseBeforeUpdateSchema();
if (CurrentDBVersion > new Version(0, 0, 0, 0) && CurrentDBVersion <= new Version(10, 1, 6)) {
var differenceObjects = new Dictionary<object, string>();
using (var reader = ExecuteReader("select [Oid], [Model] from [ModelDifferenceObject] where [Model] is not null", false)) {
while (reader.Read()) {
differenceObjects.Add(reader[0], reader[1] as string);
}
}
using (var uow = new UnitOfWork(((ObjectSpace)ObjectSpace).Session.DataLayer)) {
foreach (var differenceObject in differenceObjects) {
var modelDifferenceObject = uow.GetObjectByKey<ModelDifferenceObject>(differenceObject.Key);
var serializableDictionary = new SerializableDictionary<string, string>();
var xmlReader = XmlReader.Create(new StringReader(differenceObject.Value), new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Auto });
serializableDictionary.ReadXml(xmlReader);
var aspects = serializableDictionary["aspects"].Split(',').ToList();
var defaultAspect = serializableDictionary["DefaultAspect"];
defaultAspect = GetDefaultAspectFromVersion9(serializableDictionary, aspects, defaultAspect);
if (!string.IsNullOrEmpty(defaultAspect))
modelDifferenceObject.AspectObjects.Add(new AspectObject(uow) { Name = CaptionHelper.DefaultLanguage, Xml = defaultAspect });
foreach (var aspect in aspects.Where(aspect => !string.IsNullOrEmpty(aspect) && !string.IsNullOrEmpty(serializableDictionary[aspect]))) {
modelDifferenceObject.AspectObjects.Add(new AspectObject(uow) { Name = aspect, Xml = serializableDictionary[aspect] });
}
}
uow.CommitChanges();
}
}
}
示例6: CreateDataLayer
static IDataLayer CreateDataLayer()
{
DevExpress.Xpo.Metadata.XPDictionary dict = new DevExpress.Xpo.Metadata.ReflectionDictionary();
dict.GetDataStoreSchema(typeof(Person).Assembly);
DataSetDataStore dataStore = new DataSetDataStore(new DataSet(), AutoCreateOption.DatabaseAndSchema);
using(UnitOfWork uow = new UnitOfWork(new SimpleDataLayer(dict, dataStore))) {
uow.UpdateSchema(typeof(Person));
Person p1 = new Person(uow);
p1.FirstName = "Slava";
p1.LastName = "Donchak";
Person p2 = new Person(uow);
p2.FirstName = "Dan";
p2.LastName = "Ignatov";
Product xaf = new Product(uow);
xaf.Name = "Xaf";
xaf.Manager = p2;
Product xpo = new Product(uow);
xpo.Name = "Xpo";
xpo.Manager = p1;
uow.CommitChanges();
}
return new ThreadSafeDataLayer(dict, dataStore);
}
示例7: btnConfirm_Click
private void btnConfirm_Click(object sender, EventArgs e)
{
UnitOfWork uow;
SubPurchOrderLine subPoLine;
if (poLine.NeedQty != float.Parse(txtOKQty.Text) + float.Parse(txtDefectQty.Text))
{
XtraMessageBox.Show("良品数 + 来料不良数 需要等于要求数量");
txtOKQty.Focus();
return;
}
if (float.Parse(txtDefectQty.Text) < 0 || float.Parse(txtOKQty.Text) < 0)
{
XtraMessageBox.Show("良品数 或 来料不良数 不能少于零");
txtOKQty.Focus();
return;
}
uow = new UnitOfWork();
uow.BeginTransaction();
subPoLine = uow.FindObject<SubPurchOrderLine>(new BinaryOperator("Oid", poLine.Oid));
subPoLine.OrderStatus = SubPurchOrderLine.PurchOrderStatus.Active;
subPoLine.Save();
// 若有来料不良, 即建立一个假生产单
if (float.Parse(txtDefectQty.Text) > 0)
{
CreateProdOrderEntry(uow);
}
uow.CommitChanges();
this.Close();
}
示例8: SetupDataStore
void SetupDataStore(DataSetDataStore dataSetDataStore, UnitOfWork unitOfWork, ITypeInfo typeInfo) {
var classType = FindMappedTypeInfo(typeInfo.Name).Type;
dataSetDataStore.ObjectClassInfo = unitOfWork.Dictionary.GetClassInfo(classType);
dataSetDataStore.DynamicTypeInfo = typeInfo;
Activator.CreateInstance(classType, unitOfWork);
unitOfWork.CommitChanges();
unitOfWork.GetObjects(dataSetDataStore.ObjectClassInfo, null, new SortingCollection(), 0, 0, false, true);
}
示例9: AddDynamicModules
public void AddDynamicModules(ApplicationModulesManager moduleManager, UnitOfWork unitOfWork){
Type assemblyInfoType = TypesInfo.Instance.PersistentAssemblyInfoType;
List<IPersistentAssemblyInfo> persistentAssemblyInfos =
new XPCollection(unitOfWork, assemblyInfoType).Cast<IPersistentAssemblyInfo>().Where(info => !info.DoNotCompile &&
moduleManager.Modules.Where(@base => @base.Name == "Dynamic" + info.Name + "Module").FirstOrDefault() ==null).ToList();
_definedModules = new CompileEngine().CompileModules(persistentAssemblyInfos,GetPath());
foreach (var definedModule in _definedModules){
moduleManager.AddModule(definedModule);
}
unitOfWork.CommitChanges();
}
示例10: Remove
public void Remove(Guid id)
{
var config = new AppSettingsReader();
using (
var uow = new UnitOfWork
{
ConnectionString = ((string)config.GetValue("connect", typeof(string)))
})
{
var donneur = uow.GetObjectByKey<XpoDonneur>(id);
donneur.Etat = false;
uow.CommitChanges();
}
}
示例11: ImportObjects
public int ImportObjects(XDocument document, UnitOfWork unitOfWork) {
if (document.Root != null){
foreach (XElement element in document.Root.Nodes().OfType<XElement>()){
using (var nestedUnitOfWork = unitOfWork.BeginNestedUnitOfWork()){
ITypeInfo typeInfo = GetTypeInfo(element);
IEnumerable<XElement> elements = element.Descendants("Property");
var xElements = elements.Where(xElement => xElement.GetAttributeValue("isKey").MakeFirstCharUpper() == true.ToString());
CriteriaOperator objectKeyCriteria = GetObjectKeyCriteria(typeInfo, xElements);
CreateObject(element, nestedUnitOfWork, typeInfo, objectKeyCriteria);
nestedUnitOfWork.CommitChanges();
}
}
unitOfWork.CommitChanges();
}
return 0;
}
示例12: btnRecalSubItem_Execute
private void btnRecalSubItem_Execute(object sender, SimpleActionExecuteEventArgs e)
{
using (UnitOfWork uow = new UnitOfWork())
{
uow.BeginTransaction();
foreach (SubItem sItem in View.SelectedObjects)
{
SubItem subItem = uow.GetObjectByKey<SubItem>(sItem.Oid);
subItem.UpdateQty();
subItem.updateTimeStamp = false;
subItem.Save();
}
uow.CommitChanges();
}
View.Refresh();
}
示例13: iDelete_ItemClick
private void iDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
int[] selectedRows = gridView1.GetSelectedRows();
if (selectedRows.Length > 1) {
XtraMessageBox.Show(this, "Для удаления необходимо выбрать только один текст.",
Grammatica2._0.Properties.Resources.Grammarica20, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
ViewRecord record = gridView1.GetFocusedRow() as ViewRecord;
if (record == null) return;
using (UnitOfWork uow = new UnitOfWork()) {
GramText text = uow.GetObjectByKey<GramText>(record["Oid"]);
if (text == null) return;
if (XtraMessageBox.Show(this, string.Format("Вы действительно хотите удалить текст \"{0}\"", text.Title),
Grammatica2._0.Properties.Resources.Grammarica20, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) {
text.Delete();
uow.CommitChanges();
xpView1.Reload();
}
}
}
示例14: ImportObjects
int ImportObjects(XDocument document, UnitOfWork unitOfWork) {
_unitOfWork = unitOfWork;
if (document.Root != null) {
foreach (XElement element in document.Root.Nodes().OfType<XElement>()) {
using (NestedUnitOfWork nestedUnitOfWork = unitOfWork.BeginNestedUnitOfWork()) {
ITypeInfo typeInfo = GetTypeInfo(element);
if (typeInfo != null) {
var keys = GetKeys(element);
CriteriaOperator objectKeyCriteria = GetObjectKeyCriteria(typeInfo, keys);
if (!ReferenceEquals(objectKeyCriteria, null)) {
CreateObject(element, nestedUnitOfWork, typeInfo, objectKeyCriteria);
nestedUnitOfWork.CommitChanges();
}
}
}
}
unitOfWork.CommitChanges();
}
return 0;
}
示例15: btnRecalculateWHTotal_Execute
private void btnRecalculateWHTotal_Execute(object sender, SimpleActionExecuteEventArgs e)
{
if (View.CurrentObject != null)
{
using (UnitOfWork uow = new UnitOfWork())
{
//UnitOfWork uow = (UnitOfWork)((ObjectSpace)View.ObjectSpace).Session;
uow.BeginTransaction();
foreach (WHTotal wTotal in View.SelectedObjects)
{
WHTotal whTotal = uow.GetObjectByKey<WHTotal>(wTotal.Oid);
whTotal.CalcWHTotal();
whTotal.Save();
}
uow.CommitChanges();
}
}
}