本文整理汇总了C#中IRepository.GetEntity方法的典型用法代码示例。如果您正苦于以下问题:C# IRepository.GetEntity方法的具体用法?C# IRepository.GetEntity怎么用?C# IRepository.GetEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRepository
的用法示例。
在下文中一共展示了IRepository.GetEntity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handle
// Modify instructor with course
public static InstructorModifyAndCourses.Response Handle(IRepository repository, InstructorModifyAndCourses.Request request)
{
var commandModel = request.CommandModel;
var instructor = repository.GetEntity<Instructor>(
p => p.ID == commandModel.InstructorId,
new EagerLoadingQueryStrategy<Instructor>(
p => p.Courses,
p => p.OfficeAssignment));
var container = instructor.Modify(repository, request.CommandModel);
var validationDetails = repository.Save(container);
return new InstructorModifyAndCourses.Response(validationDetails);
}
示例2: Handle
// Update department
#region Update department
public static DepartmentUpdate.Response Handle(IRepository repository, DepartmentUpdate.Request request)
{
var validationDetails = Validator.ValidateRequest(request, repository);
if (validationDetails.HasValidationIssues)
return new DepartmentUpdate.Response(validationDetails);
var commandModel = request.CommandModel;
var currentDept = repository.GetEntity<Department>(
p => p.DepartmentID == commandModel.DepartmentID,
new AsNoTrackingQueryStrategy());
var rowVersion = default(byte[]);
var container = currentDept.Modify(request.CommandModel);
validationDetails = repository.Save(container, dbUpdateEx => OnUpdateFailedFunc(repository, dbUpdateEx, commandModel, ref rowVersion));
return new DepartmentUpdate.Response(validationDetails, rowVersion);
}
示例3: OnUpdateFailedFunc
private static ValidationMessageCollection OnUpdateFailedFunc(IRepository repository, DbUpdateConcurrencyException dbUpdateEx, DepartmentUpdate.CommandModel commandModel, ref byte[] rowVersion)
{
var validationMessages = new ValidationMessageCollection();
var entry = dbUpdateEx.Entries.Single();
var databaseEntry = entry.GetDatabaseValues();
if (databaseEntry == null)
{
validationMessages.Add(string.Empty, "Unable to save changes. The department was deleted by another user.");
return validationMessages;
}
var databaseValues = (Department)databaseEntry.ToObject();
rowVersion = databaseValues.RowVersion;
if (databaseValues.Name != commandModel.Name)
validationMessages.Add(nameof(commandModel.Name), "Current value: " + databaseValues.Name);
if (databaseValues.Budget != commandModel.Budget)
validationMessages.Add(nameof(commandModel.Budget), "Current value: " + string.Format("{0:c}", databaseValues.Budget));
if (databaseValues.StartDate != commandModel.StartDate)
validationMessages.Add(nameof(commandModel.StartDate), "Current value: " + string.Format("{0:d}", databaseValues.StartDate));
if (databaseValues.InstructorID != commandModel.InstructorID)
validationMessages.Add(nameof(commandModel.InstructorID), "Current value: " + repository.GetEntity<Instructor>(p => p.ID == databaseValues.InstructorID.Value).FullName);
validationMessages.Add(string.Empty, "The record you attempted to edit "
+ "was modified by another user after you got the original value. The "
+ "edit operation was canceled and the current values in the database "
+ "have been displayed. If you still want to edit this record, click "
+ "the Save button again. Otherwise click the Back to List hyperlink.");
return validationMessages;
}