本文整理汇总了C#中UnitOfWork.GetObjectByKey方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.GetObjectByKey方法的具体用法?C# UnitOfWork.GetObjectByKey怎么用?C# UnitOfWork.GetObjectByKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.GetObjectByKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessMessage
/// <summary>
/// Метод принимает сообщение от клиента
/// </summary>
/// <param name="context">Идентификатор клиента</param>
/// <param name="message">Строка сообщения</param>
public void ProcessMessage(Guid context, String message, Object[] param = null)
{
// Получаем объект для работы с данными БД
//ThreadSafeDataLayer
UnitOfWork uow = new UnitOfWork((this.Application.CreateObjectSpace() as XPObjectSpace).Session.DataLayer);
if (uow == null)
throw new Exception("Error occurred while creating UnitOfWork object.");
// Находим обследование по ИД
IExamination examination = uow.GetObjectByKey<IExamination>(context);
if (examination == null)
{
DevExpress.Persistent.Base.Tracing.Tracer.LogError("ProcessMessage({0}, {1}) Examination [id={0}] is not found in the database", context, message);
return;
}
// Выполняем полученную команду
ExecuteCommand(message, uow, examination, param);
// Обновляем главное окно
//UpdateWindow(context);
OnViewUpdate();
}
示例2: MapDonneur
public static XpoDonneur MapDonneur(Donneur donneur, UnitOfWork uow)
{
XpoDonneur xpoDonneur;
if (donneur.NewObject)
{
xpoDonneur = new XpoDonneur(uow)
{
Oid = donneur.Id
};
}
else
{
xpoDonneur= uow.GetObjectByKey<XpoDonneur>(donneur.Id);
}
xpoDonneur.Nom = donneur.Nom;
xpoDonneur.Prenom = donneur.Prenom;
xpoDonneur.DateNaissance = donneur.DateNaissance;
xpoDonneur.Sexe = donneur.Sexe;
xpoDonneur.Adresse = donneur.Adresse;
xpoDonneur.Mail = donneur.Mail;
xpoDonneur.NumTel = donneur.NumTel;
xpoDonneur.Etat = donneur.Etat;
return xpoDonneur;
}
示例3: 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);
}
示例4: 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();
}
示例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: TextEditForm
public TextEditForm(Guid oid) {
InitializeComponent();
uow = new UnitOfWork();
if (oid == Guid.Empty) {
gramText = new GramText(uow);
} else {
gramText = uow.GetObjectByKey<GramText>(oid);
}
LoadGramText();
}
示例7: CurrentCustomerUsingUnitOfWork
public static Customer CurrentCustomerUsingUnitOfWork(UnitOfWork uow)
{
Customer customer = null;
if (IsLoggedIn())
{
customer = uow.GetObjectByKey<Customer>(CurrentCustomer().Oid);
}
return customer;
}
示例8: FindBy
public Donneur FindBy(Guid id)
{
var config = new AppSettingsReader();
using (
var uow = new UnitOfWork
{
ConnectionString = ((string)config.GetValue("connect", typeof(string)))
})
{
var donneur = uow.GetObjectByKey<Donneur>(id);
return donneur;
}
}
示例9: 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();
}
}
示例10: 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();
}
示例11: btnRecalcSubItemMonthly_Execute
private void btnRecalcSubItemMonthly_Execute(object sender, SimpleActionExecuteEventArgs e)
{
if (View.CurrentObject == null)
return;
using (UnitOfWork uow = new UnitOfWork())
{
uow.BeginTransaction();
foreach (SubItemMonthly iMonthly in View.SelectedObjects)
{
SubItemMonthly itemMonthly = uow.GetObjectByKey<SubItemMonthly>(iMonthly.Oid);
itemMonthly.UpdateQty();
itemMonthly.Save();
}
uow.CommitChanges();
View.ObjectSpace.Refresh();
}
}
示例12: 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();
}
}
}
示例13: 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();
}
}
}
示例14: MapUtilisateur
public static XpoUtilisateur MapUtilisateur(Utilisateur utilisateur, UnitOfWork uow)
{
XpoUtilisateur xpoUtilisateur;
if (utilisateur.NewObject)
{
xpoUtilisateur = new XpoUtilisateur(uow)
{
Oid = utilisateur.Id
};
}
else
{
xpoUtilisateur = uow.GetObjectByKey<XpoUtilisateur>(utilisateur.Id);
}
xpoUtilisateur.Pseudo = utilisateur.Pseudo;
xpoUtilisateur.Mdp = utilisateur.Mdp;
xpoUtilisateur.Administrateur = utilisateur.Administrateur;
xpoUtilisateur.Type = utilisateur.Type;
xpoUtilisateur.Etat = utilisateur.Etat;
return xpoUtilisateur;
}
示例15: TestForm
public TestForm(List<Guid> textList) {
InitializeComponent();
uow = new UnitOfWork();
int testCount = 0;
foreach (Guid oid in textList) {
if (oid == Guid.Empty) {
continue;
}
GramText text = uow.GetObjectByKey<GramText>(oid);
if (text == null) continue;
testCount += text.Tests.Count;
gramTextList.Add(text);
}
gramTestResult = new GramTestResult(uow);
gramTestResult.Text = gramTextList.Count > 0 ? gramTextList[0] : null;
gramTestResult.TestCount = testCount;
gramTestResult.TestSkippedCount = 0;
gramTestResult.MistakeCount = 0;
gramTestResult.ResultingScore = 0;
gramTestResult.ExecutionTime = 0;
Text = "";
richEdit.ReadOnly = true;
startTime = DateTime.Now;
}