本文整理汇总了C#中ServiceContext.AddObject方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContext.AddObject方法的具体用法?C# ServiceContext.AddObject怎么用?C# ServiceContext.AddObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceContext
的用法示例。
在下文中一共展示了ServiceContext.AddObject方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public void Add(TimeoutData timeout)
{
var context = new ServiceContext(account.TableEndpoint.ToString(), account.Credentials);
var hash = Hash(timeout);
TimeoutDataEntity timeoutDataEntity;
if (TryGetTimeoutData(context, hash, string.Empty, out timeoutDataEntity)) return;
var stateAddress = Upload(timeout.State, hash);
var headers = Serialize(timeout.Headers);
if (!TryGetTimeoutData(context, timeout.Time.ToString(partitionKeyScope), stateAddress, out timeoutDataEntity))
context.AddObject(ServiceContext.TimeoutDataEntityTableName,
new TimeoutDataEntity(timeout.Time.ToString(partitionKeyScope), stateAddress)
{
Destination = timeout.Destination.ToString(),
SagaId = timeout.SagaId,
StateAddress = stateAddress,
Time = timeout.Time,
CorrelationId = timeout.CorrelationId,
OwningTimeoutManager = timeout.OwningTimeoutManager,
Headers = headers
});
if (timeout.SagaId != default(Guid) && !TryGetTimeoutData(context, timeout.SagaId.ToString(), stateAddress, out timeoutDataEntity))
context.AddObject(ServiceContext.TimeoutDataEntityTableName,
new TimeoutDataEntity(timeout.SagaId.ToString(), stateAddress)
{
Destination = timeout.Destination.ToString(),
SagaId = timeout.SagaId,
StateAddress = stateAddress,
Time = timeout.Time,
CorrelationId = timeout.CorrelationId,
OwningTimeoutManager = timeout.OwningTimeoutManager,
Headers = headers
});
context.AddObject(ServiceContext.TimeoutDataEntityTableName,
new TimeoutDataEntity(stateAddress, string.Empty)
{
Destination = timeout.Destination.ToString(),
SagaId = timeout.SagaId,
StateAddress = stateAddress,
Time = timeout.Time,
CorrelationId = timeout.CorrelationId,
OwningTimeoutManager = timeout.OwningTimeoutManager,
Headers = headers
});
context.SaveChanges();
}
示例2: Notify
public void Notify(MessageContracts.StockNotifyRequestMessage request)
{
using (OrganizationServiceProxy proxy = CRMHelper.Connect())
{
ServiceContext context = new ServiceContext(proxy);
foreach(StockItemDataContract item in request.Items)
{
bool add = false;
new_stock record = (from a in context.new_stockSet
where a.new_vinnumber == item.Stock.new_vinnumber
select a).FirstOrDefault();
if(record == null)
{
add = true;
record = new new_stock();
}
record.new_internalvehiclenumber = item.Stock.new_internalvehiclenumber;
record.new_vinnumber = item.Stock.new_vinnumber;
record.new_enginenumber = item.Stock.new_enginenumber;
record.new_sapvehiclemodelcode = item.Stock.new_sapvehiclemodelcode;
record.new_plantsap = item.Stock.new_plantsap;
record.new_storagelocation = item.Stock.new_storagelocation;
record.new_stockvalue = item.Stock.new_stockvalue;
record.new_status = item.Stock.new_status;
record.new_vehicleguid = item.Stock.new_vehicleguid;
if(add)
context.AddObject(record);
else
context.UpdateObject(record);
}
context.SaveChanges();
}
}
示例3: Notify
//.........这里部分代码省略.........
record.new_saporderno = item.Invoice.new_saporderno;
record.new_client = item.Invoice.new_client;
if (contact != null)
record.CustomerId = contact.ToEntityReference();
if (order != null)
record.SalesOrderId = order.ToEntityReference();
record.new_precedingdocument = item.Invoice.new_precedingdocument;
if (salesOffice != null)
record.new_salesoffice = salesOffice.ToEntityReference();
if(plant != null)
record.new_plant = plant.ToEntityReference();
record.new_customeradviser = item.Invoice.new_customeradviser;
record.new_billingdate = item.Invoice.new_billingdate;
record.new_licenseplatenumber = item.Invoice.new_licenseplatenumber;
record.new_country = item.Invoice.new_country;
record.new_counterreading = item.Invoice.new_counterreading;
record.new_counterunit = item.Invoice.new_counterunit;
record.new_orderstatus = item.Invoice.new_orderstatus;
record.new_netvalue = item.Invoice.new_netvalue;
record.new_vehicleguid = item.Invoice.new_vehicleguid;
if (invoiceType != null)
record.new_invoicetype = invoiceType.ToEntityReference();
if (add)
context.AddObject(record);
else
context.UpdateObject(record);
//Invoice Detail
//We will nowdelete all line item s and readd them
//if we do not do this we will get duplicate records.
if (record.invoice_details != null)
{
foreach (InvoiceDetail detail in record.invoice_details)
context.DeleteObject(detail);
}
foreach (InvoiceDetail lineItem in item.InvoiceDetails)
{
InvoiceDetail detail = new InvoiceDetail();
//new_material
new_modelsalescode material = null;
if(detail.new_material != null)
{
material = (from m in context.new_modelsalescodeSet
where m.new_name == lineItem.new_material.Name
select m).FirstOrDefault();
}
//Plant
Territory detailPlant = null;
示例4: UpdateSuccesfullRead
private void UpdateSuccesfullRead(ServiceContext context, TimeoutManagerDataEntity read)
{
if (read == null)
{
read = new TimeoutManagerDataEntity(Configure.EndpointName, string.Empty){
LastSuccessfullRead = DateTime.UtcNow
};
context.AddObject(ServiceContext.TimeoutManagerDataEntityTableName, read);
}
else
{
read.LastSuccessfullRead = DateTime.UtcNow;
context.UpdateObject(read);
}
context.SaveChanges(SaveChangesOptions.ReplaceOnUpdate);
}
示例5: MigrateExistingTimeouts
private void MigrateExistingTimeouts(ServiceContext context)
{
var existing = (from c in context.TimeoutData
where c.PartitionKey == "TimeoutData"
select c).ToList();
foreach(var timeout in existing)
{
TimeoutDataEntity timeoutDataEntity;
if (!TryGetTimeoutData(context, timeout.Time.ToString(partitionKeyScope), timeout.RowKey, out timeoutDataEntity))
context.AddObject(ServiceContext.TimeoutDataEntityTableName,
new TimeoutDataEntity(timeout.Time.ToString(partitionKeyScope), timeout.RowKey)
{
Destination = timeout.Destination,
SagaId = timeout.SagaId,
StateAddress = timeout.RowKey,
Time = timeout.Time,
CorrelationId = timeout.CorrelationId,
OwningTimeoutManager = timeout.OwningTimeoutManager
});
if (!TryGetTimeoutData(context, timeout.SagaId.ToString(), timeout.RowKey, out timeoutDataEntity))
context.AddObject(ServiceContext.TimeoutDataEntityTableName,
new TimeoutDataEntity(timeout.SagaId.ToString(), timeout.RowKey)
{
Destination = timeout.Destination,
SagaId = timeout.SagaId,
StateAddress = timeout.RowKey,
Time = timeout.Time,
CorrelationId = timeout.CorrelationId,
OwningTimeoutManager = timeout.OwningTimeoutManager
});
if (!TryGetTimeoutData(context, timeout.RowKey, string.Empty, out timeoutDataEntity))
context.AddObject(ServiceContext.TimeoutDataEntityTableName,
new TimeoutDataEntity(timeout.RowKey, string.Empty)
{
Destination = timeout.Destination,
SagaId = timeout.SagaId,
StateAddress = timeout.RowKey,
Time = timeout.Time,
CorrelationId = timeout.CorrelationId,
OwningTimeoutManager = timeout.OwningTimeoutManager
});
context.DeleteObject(timeout);
context.SaveChanges();
}
}