本文整理汇总了C#中CmsEntities.Entry方法的典型用法代码示例。如果您正苦于以下问题:C# CmsEntities.Entry方法的具体用法?C# CmsEntities.Entry怎么用?C# CmsEntities.Entry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CmsEntities
的用法示例。
在下文中一共展示了CmsEntities.Entry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveControlSystemAlarmMappingCentums
public DbOperationResult SaveControlSystemAlarmMappingCentums(List<ControlSystemAlarmMappingCentum> centums)
{
var result = new DbOperationResult();
try
{
using (var cee = new CmsEntities())
{
foreach (var centum in centums)
{
var dbMatch = (from x in cee.ControlSystemAlarmMappingCentums
where x.Id == centum.Id
select x).FirstOrDefault();
if (dbMatch != null)
{
//Update
cee.Entry(dbMatch).CurrentValues.SetValues(centum);
cee.SaveChanges();
}
else
{
//insert
cee.ControlSystemAlarmMappingCentums.Add(centum);
cee.SaveChanges();
}
}
}
}
catch (Exception ex)
{
log.Error("", ex, ex.ToString());
result.ServerErrorMessages.Add(string.Format("Could not Save ControlSystemAlarmMappingCentum record.{0}{1}", Environment.NewLine, ex.Message));
}
return result;
}
示例2: SaveRole
public Role SaveRole(Role role)
{
using (CmsEntities cee = new CmsEntities())
{
Role dbRole = (from x in cee.Roles where x.Name == role.Name select x).FirstOrDefault();
if (dbRole != null)
{
cee.Entry(dbRole).CurrentValues.SetValues(role);
}
else
{
cee.Roles.Add(role);
}
cee.SaveChanges();
}
return role;
}
示例3: SavePipeProperty
public PipeProperty SavePipeProperty(PipeProperty pipeProperty)
{
using (CmsEntities cee = new CmsEntities())
{
PipeProperty original = (from x in cee.PipeProperties where x.Id == pipeProperty.Id select x).FirstOrDefault();
if (original == null)
{
cee.PipeProperties.Add(pipeProperty);
}
else
{
cee.Entry(original).CurrentValues.SetValues(pipeProperty);
}
cee.SaveChanges();
}
return pipeProperty;
}
示例4: SaveInstrument
public DbOperationResult<QuickInstrument> SaveInstrument(Instrument equip, int userId)
{
try
{
using (CmsEntities cee = new CmsEntities())
{
Instrument originalObject = (from x in cee.Instruments
.Include("InstrumentComponents")
.Include("InstrumentComponents.InstrumentComponentType")
.Include("CalibrationComponents")
.Include("CalibrationComponents.CalibrationComponentType")
where x.Id == equip.Id
select x).FirstOrDefault();
if (originalObject != null)
{
IEnumerable<InstrumentComponent> instrumentComponentsToBeDeleted = (from x in originalObject.InstrumentComponents
where !equip.InstrumentComponents.Any(x1 => x1.Id == x.Id)
select x);
bool hasRevHist = false;
var rh = BuildRevisionHistory(equip, userId, instrumentComponentsToBeDeleted, cee, out hasRevHist);
foreach (var instrumentComponent in instrumentComponentsToBeDeleted)
{
DeleteInstrumentComponent(instrumentComponent);
}
IEnumerable<CalibrationComponent> calibrationComponentsToBeDeleted = (from x in originalObject.CalibrationComponents
where !equip.CalibrationComponents.Any(x1 => x1.Id == x.Id )
select x);
BuildRevisionHistory(equip, userId, calibrationComponentsToBeDeleted, rh, hasRevHist, cee);
BuildRevisionHistory(equip, cee);
foreach (var calibrationComponent in calibrationComponentsToBeDeleted)
{
DeleteCalibrationComponent(calibrationComponent);
}
SaveInstrumentComponents(equip.InstrumentComponents.ToList(), userId);
SaveCalibrationComponents(equip.CalibrationComponents.ToList());
SaveInstrumentAttachments(equip.InstrumentAttachments.ToList());
SaveInstrumentRelatedIssues(equip, cee);
SaveInstrumentDocuments(equip, cee);
cee.Entry(originalObject).CurrentValues.SetValues(equip);
cee.SaveChanges();
}
else
{
equip.InstrumentType = null;
equip.Area = null;
equip.IsActive = true;
equip.VerificationFrequencyId = 1;
cee.Instruments.Add(equip);
cee.SaveChanges();
}
QuickInstrument quickInstrument = BuildQuickInstrument(cee, equip.Id);
return new DbOperationResult<QuickInstrument> { EntityResult = quickInstrument };
}
}
catch (Exception ex)
{
log.Error("", ex, ex.ToString());
return BuildOperationalErrorResults<QuickInstrument>(ex);
}
}
示例5: SaveInstrumentProperty
public InstrumentProperty SaveInstrumentProperty(InstrumentProperty instrumentProperty)
{
using (CmsEntities cee = new CmsEntities())
{
InstrumentProperty original = (from x in cee.InstrumentProperties where x.Id == instrumentProperty.Id select x).FirstOrDefault();
if (original == null)
{
cee.InstrumentProperties.Add(instrumentProperty);
}
else
{
cee.Entry(original).CurrentValues.SetValues(instrumentProperty);
}
cee.SaveChanges();
}
return instrumentProperty;
}
示例6: SaveElectricalEquipmentProperty
public DbOperationResult<ElectricalEquipmentProperty> SaveElectricalEquipmentProperty(ElectricalEquipmentProperty controlSystemProperty)
{
DbOperationResult<ElectricalEquipmentProperty> dbOperationResult = new DbOperationResult<ElectricalEquipmentProperty>();
try
{
using (CmsEntities cee = new CmsEntities())
{
ElectricalEquipmentProperty original = (from x in cee.ElectricalEquipmentProperties where x.Id == controlSystemProperty.Id select x).FirstOrDefault();
if (original == null)
{
cee.ElectricalEquipmentProperties.Add(controlSystemProperty);
}
else
{
cee.Entry(original).CurrentValues.SetValues(controlSystemProperty);
}
cee.SaveChanges();
dbOperationResult.EntityResult = controlSystemProperty;
}
}
catch (Exception ex)
{
log.Error("", ex, ex.ToString());
dbOperationResult.ServerErrorMessages = BuildOperationalErrorResults(ex).ServerErrorMessages;
return dbOperationResult;
}
return dbOperationResult;
}
示例7: SaveElectricalEquipment
public DbOperationResult<QuickElectrical> SaveElectricalEquipment(ElectricalEquipment equip, int userId)
{
try
{
using (CmsEntities cee = new CmsEntities())
{
var originalObject = (from x in cee.ElectricalEquipments
.Include("ElectricalEquipmentComponents")
.Include("ElectricalEquipmentComponents.ElectricalEquipmentComponentType")
where x.Id == equip.Id
select x).FirstOrDefault();
if (originalObject != null)
{
IEnumerable<ElectricalEquipmentComponent> electricalComponentsToBeDeleted = from x in originalObject.ElectricalEquipmentComponents
where !equip.ElectricalEquipmentComponents.Any(x1 => x1.Id == x.Id)
select x;
BuildRevisonHistory(equip, userId, electricalComponentsToBeDeleted, cee);
BuildRevisionHistory(equip, cee);
foreach (var electricalComponent in electricalComponentsToBeDeleted)
{
DeleteElectricalEquipmentComponent(electricalComponent);
}
SaveElectricalEquipmentComponents(equip.ElectricalEquipmentComponents.ToList(), cee, equip.Id, userId);
SaveElectricalAttachments(equip.ElectricalEquipmentAttachments.ToList());
SaveElectricalRelatedIssues(equip, cee);
SaveElectricalDocuments(equip, cee);
cee.Entry(originalObject).CurrentValues.SetValues(equip);
cee.SaveChanges();
}
else
{
equip.ElectricalEquipmentType = null;
equip.Area = null;
equip.IsActive = true;
cee.ElectricalEquipments.Add(equip);
cee.SaveChanges();
}
QuickElectrical quickElectrical = BuildQuickElectrical(cee, equip.Id);
return new DbOperationResult<QuickElectrical> { EntityResult = quickElectrical };
}
}
catch (Exception ex)
{
log.Error("", ex, ex.ToString());
return BuildOperationalErrorResults<QuickElectrical>(ex);
}
}
示例8: SaveControlSystemTuningParemeters
private void SaveControlSystemTuningParemeters(List<ControlSystemComponent> controlSystemComponents)
{
using (var cee = new CmsEntities())
{
foreach (var controlSystemComponent in controlSystemComponents)
{
foreach (var controlSystemTuningPropertyValue in controlSystemComponent.ControlSystemTuningPropertyValues)
{
var qq = (from x in cee.ControlSystemTuningPropertyValues
where x.Id == controlSystemTuningPropertyValue.Id
select x).FirstOrDefault();
if (qq != null)
{
cee.Entry(qq).CurrentValues.SetValues(controlSystemTuningPropertyValue);
}
else
{
cee.ControlSystemTuningPropertyValues.Add(controlSystemTuningPropertyValue);
}
}
cee.SaveChanges();
}
}
}
示例9: SaveMechanicalEquipmentComponents
public bool SaveMechanicalEquipmentComponents(List<MechanicalEquipmentComponent> mechanicalComponents, int userId)
{
using (CmsEntities cee = new CmsEntities())
{
foreach (var mechanicalComponent in mechanicalComponents)
{
var q = (from x in cee.MechanicalEquipmentComponents
where x.Id == mechanicalComponent.Id
select x).FirstOrDefault();
if (q != null)
{
if (q.LastInspectedDate != mechanicalComponent.LastInspectedDate)
{
MechanicalEquipmentRevisionHistory rv = new MechanicalEquipmentRevisionHistory
{
MechanicalEquipmentId = mechanicalComponent.MechanicalEquipmentId,
Date = DateTime.Now,
UserId = userId,
Description = string.Format("Component '{0}': Last Inspected Date changed from '{1}' to '{2}'.",mechanicalComponent.Name, q.LastInspectedDate, mechanicalComponent.LastInspectedDate),
IsSystemMessage = true
};
AddMechanicalRevisionHistoryInternal(rv, cee);
}
//Update Mechanical Componet
cee.Entry(q).CurrentValues.SetValues(mechanicalComponent);
}
else
{
q = new MechanicalEquipmentComponent();
q.MechanicalEquipmentId = mechanicalComponent.MechanicalEquipmentId;
q.MechanicalEquipmentComponentTypeId = mechanicalComponent.MechanicalEquipmentComponentTypeId;
q.Name = mechanicalComponent.Name;
q.Ordinal = mechanicalComponent.Ordinal;
q.NextInspectionDate = mechanicalComponent.NextInspectionDate;
q.LastInspectedById = mechanicalComponent.LastInspectedById;
q.LastInspectedDate = mechanicalComponent.LastInspectedDate;
q.LastModifiedById = mechanicalComponent.LastModifiedById;
q.LastModifiedDate = mechanicalComponent.LastModifiedDate;
q.Description = mechanicalComponent.Description;
q.ManufacturerId = mechanicalComponent.ManufacturerId;
q.ModelId = mechanicalComponent.ModelId;
//Add new Mechanical Component
cee.MechanicalEquipmentComponents.Add(q);
}
foreach (var mechanicalComponentPropertyValue in mechanicalComponent.MechanicalPropertyValues)
{
var qq = (from x in cee.MechanicalPropertyValues
where x.Id == mechanicalComponentPropertyValue.Id
select x).FirstOrDefault();
if (qq != null)
{
cee.Entry(qq).CurrentValues.SetValues(mechanicalComponentPropertyValue);
}
else
{
cee.MechanicalPropertyValues.Add(mechanicalComponentPropertyValue);
}
}
cee.SaveChanges();
}
}
return true;
}
示例10: SaveControlSystemTuningProperty
public ControlSystemTuningProperty SaveControlSystemTuningProperty(ControlSystemTuningProperty controlSystemTuningProperty)
{
using (var cee = new CmsEntities())
{
var original = (from x in cee.ControlSystemTuningProperties where x.Id == controlSystemTuningProperty.Id select x).FirstOrDefault();
if (original == null)
{
cee.ControlSystemTuningProperties.Add(controlSystemTuningProperty);
}
else
{
cee.Entry(original).CurrentValues.SetValues(controlSystemTuningProperty);
}
cee.SaveChanges();
}
return controlSystemTuningProperty;
}
示例11: SaveControlSystemTestingProperties
private void SaveControlSystemTestingProperties(ControlSystem controlSystem)
{
using (var cee = new CmsEntities())
{
foreach (var propertyValue in controlSystem.ControlSystemTestingPropertyValues)
{
var qq = (from x in cee.ControlSystemTestingPropertyValues
where x.Id == propertyValue.Id
select x).FirstOrDefault();
if (qq != null)
{
cee.Entry(qq).CurrentValues.SetValues(propertyValue);
}
else
{
cee.ControlSystemTestingPropertyValues.Add(propertyValue);
}
cee.SaveChanges();
}
}
}
示例12: SaveControlSystemTestingProperty
public DbOperationResult<ControlSystemTestingProperty> SaveControlSystemTestingProperty(ControlSystemTestingProperty property)
{
DbOperationResult<ControlSystemTestingProperty> result = new DbOperationResult<ControlSystemTestingProperty>();
try
{
using (var cee = new CmsEntities())
{
var original = (from x in cee.ControlSystemTestingProperties where x.Id == property.Id select x).FirstOrDefault();
if (original == null)
{
cee.ControlSystemTestingProperties.Add(property);
cee.SaveChanges();
result.EntityResult = property;
}
else
{
cee.Entry(original).CurrentValues.SetValues(property);
cee.SaveChanges();
result.EntityResult = original;
}
}
}
catch (Exception ex)
{
log.Error("", ex, ex.ToString());
result.ServerErrorMessages.Add(string.Format("Could not Save Control System Testing Property.{0}{1}", Environment.NewLine, ex.Message));
}
return result;
}
示例13: SaveControlSystemInterlocks
public DbOperationResult SaveControlSystemInterlocks(List<Interlock> controlSystemInterlocks)
{
var result = new DbOperationResult();
using (var cee = new CmsEntities())
{
try
{
foreach (var interlock in controlSystemInterlocks)
{
var q = (from x in cee.Interlocks
where x.Id == interlock.Id
select x).FirstOrDefault();
if (q != null)
{
//Update Interlock
cee.Entry(q).CurrentValues.SetValues(interlock);
}
else
{
q = new Interlock
{
ControlSystemId = interlock.ControlSystemId,
InterlockTypeId = interlock.InterlockTypeId,
Number = interlock.Number,
Cause = interlock.Cause,
Ordinal = interlock.Ordinal,
LastModifiedById = interlock.LastModifiedById,
LastModifiedDate = interlock.LastModifiedDate,
Description = interlock.Description
};
//Add new Interlock
cee.Interlocks.Add(q);
}
foreach (var interlockPropertyValue in interlock.InterlockPropertyValues)
{
var qq = (from x in cee.InterlockPropertyValues
where x.Id == interlockPropertyValue.Id
select x).FirstOrDefault();
if (qq != null)
{
cee.Entry(qq).CurrentValues.SetValues(interlockPropertyValue);
}
else
{
cee.InterlockPropertyValues.Add(interlockPropertyValue);
}
}
SaveInterlockRisks(interlock, cee);
cee.SaveChanges();
}
}
catch (Exception ex)
{
result.ServerErrorMessages.Add(String.Format("Error Saving Control System Interlocks: {0}", ex.Message));
}
}
return result;
}
示例14: SaveControlSystemComponents
public DbOperationResult SaveControlSystemComponents(List<ControlSystemComponent> controlSystemComponents)
{
var result = new DbOperationResult();
using (var cee = new CmsEntities())
{
try
{
foreach (var controlSystemComponent in controlSystemComponents)
{
var q = (from x in cee.ControlSystemComponents
where x.Id == controlSystemComponent.Id
select x).FirstOrDefault();
if (q != null)
{
//Update ControlSystem Componet
q.ControlSystemId = controlSystemComponent.ControlSystemId;
q.ControlSystemComponentTypeId = controlSystemComponent.ControlSystemComponentTypeId;
q.Name = controlSystemComponent.Name;
q.Ordinal = controlSystemComponent.Ordinal;
q.NextInspectionDate = controlSystemComponent.NextInspectionDate;
q.LastInspectedById = controlSystemComponent.LastInspectedById;
q.LastInspectedDate = controlSystemComponent.LastInspectedDate;
q.LastModifiedById = controlSystemComponent.LastModifiedById;
q.LastModifiedDate = controlSystemComponent.LastModifiedDate;
q.Description = controlSystemComponent.Description;
q.ManufacturerId = controlSystemComponent.ManufacturerId;
q.ModelId = controlSystemComponent.ModelId;
}
else
{
q = new ControlSystemComponent();
q.ControlSystemId = controlSystemComponent.ControlSystemId;
q.ControlSystemComponentTypeId = controlSystemComponent.ControlSystemComponentTypeId;
q.Name = controlSystemComponent.Name;
q.Ordinal = controlSystemComponent.Ordinal;
q.NextInspectionDate = controlSystemComponent.NextInspectionDate;
q.LastInspectedById = controlSystemComponent.LastInspectedById;
q.LastInspectedDate = controlSystemComponent.LastInspectedDate;
q.LastModifiedById = controlSystemComponent.LastModifiedById;
q.LastModifiedDate = controlSystemComponent.LastModifiedDate;
q.Description = controlSystemComponent.Description;
q.ManufacturerId = controlSystemComponent.ManufacturerId;
q.ModelId = controlSystemComponent.ModelId;
//Add new ControlSystem Component
cee.ControlSystemComponents.Add(q);
}
foreach (var controlSystemComponentPropertyValue in controlSystemComponent.ControlSystemPropertyValues)
{
var qq = (from x in cee.ControlSystemPropertyValues
where x.Id == controlSystemComponentPropertyValue.Id
select x).FirstOrDefault();
if (qq != null)
{
cee.Entry(qq).CurrentValues.SetValues(controlSystemComponentPropertyValue);
}
else
{
cee.ControlSystemPropertyValues.Add(controlSystemComponentPropertyValue);
}
}
cee.SaveChanges();
}
}
catch (Exception ex)
{
result.ServerErrorMessages.Add(String.Format("Error moving components: {0}", ex.Message));
}
}
return result;
}
示例15: SaveMobilePlantComponents
private void SaveMobilePlantComponents(IEnumerable<MobilePlantComponent> mobilePlantComponents, CmsEntities cee, int mobilePlantEquipmentId, int userId)
{
foreach (var mobilePlantComponent in mobilePlantComponents)
{
var q = (from x in cee.MobilePlantComponents
where x.Id == mobilePlantComponent.Id
select x).FirstOrDefault();
if (q != null)
{
if (q.LastInspectedDate != mobilePlantComponent.LastInspectedDate)
{
MobilePlantRevisionHistory rv = new MobilePlantRevisionHistory
{
MobilePlantId = mobilePlantEquipmentId,
Date = DateTime.Now,
UserId = userId,
Description = string.Format("Component '{0}': Last Inspected Date changed from '{1}' to '{2}'.", mobilePlantComponent.Name, q.LastInspectedDate, mobilePlantComponent.LastInspectedDate),
IsSystemMessage = true
};
AddMobilePlantRevisionHistoryInternal(rv, cee);
}
//Update
cee.Entry(q).CurrentValues.SetValues(mobilePlantComponent);
}
else
{
//Add new
q = new MobilePlantComponent();
q.MobilePlantId = mobilePlantComponent.MobilePlantId;
q.MobilePlantComponentTypeId = mobilePlantComponent.MobilePlantComponentTypeId;
q.Name = mobilePlantComponent.Name;
q.Ordinal = mobilePlantComponent.Ordinal;
q.NextInspectionDate = mobilePlantComponent.NextInspectionDate;
q.LastInspectedById = mobilePlantComponent.LastInspectedById;
q.LastInspectedDate = mobilePlantComponent.LastInspectedDate;
q.LastModifiedById = mobilePlantComponent.LastModifiedById;
q.LastModifiedDate = mobilePlantComponent.LastModifiedDate;
q.Description = mobilePlantComponent.Description;
q.ManufacturerId = mobilePlantComponent.ManufacturerId;
q.ModelId = mobilePlantComponent.ModelId;
cee.MobilePlantComponents.Add(q);
}
foreach (var mobilePlantComponentPropertyValue in mobilePlantComponent.MobilePlantPropertyValues)
{
var qq = (from x in cee.MobilePlantPropertyValues
where x.Id == mobilePlantComponentPropertyValue.Id
select x).FirstOrDefault();
if (qq != null)
{
cee.Entry(qq).CurrentValues.SetValues(mobilePlantComponentPropertyValue);
}
else
{
cee.MobilePlantPropertyValues.Add(mobilePlantComponentPropertyValue);
}
}
}
}