当前位置: 首页>>代码示例>>C#>>正文


C# ServiceContext.SaveChanges方法代码示例

本文整理汇总了C#中ServiceContext.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContext.SaveChanges方法的具体用法?C# ServiceContext.SaveChanges怎么用?C# ServiceContext.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ServiceContext的用法示例。


在下文中一共展示了ServiceContext.SaveChanges方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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();
            }
        }
开发者ID:britehouse,项目名称:toyota-tsusho-new,代码行数:40,代码来源:StockService.cs

示例2: Notify


//.........这里部分代码省略.........
                    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;

                        if (lineItem.new_plant != null)
                        {
                            entity = (from p in context.CreateQuery("territory")
                                      where p["new_sapcode"] == lineItem.new_plant.Name
                                      select p).FirstOrDefault();

                            if (entity != null)
                                detailPlant = entity.ToEntity<Territory>();
                        }

                        //Populate Invoice Detail

                        detail.LineItemNumber = lineItem.LineItemNumber;
                        detail.new_pricingreferencematerial = lineItem.new_pricingreferencematerial;
                        detail.new_lvhierno = lineItem.new_lvhierno;

                        if (material != null)
                            detail.new_material = material.ToEntityReference();

                        detail.new_materialgroup = lineItem.new_materialgroup;
                        detail.ProductDescription = lineItem.ProductDescription;
                        detail.IsPriceOverridden = lineItem.IsPriceOverridden;
                        detail.IsProductOverridden = lineItem.IsProductOverridden;
                        detail.new_description1 = lineItem.new_description1;
                        detail.new_itemcategory = lineItem.new_itemcategory;
                        detail.new_deleteitem = lineItem.new_deleteitem;
                        detail.Quantity = lineItem.Quantity;
                        detail.new_targetqtyuom = lineItem.new_targetqtyuom;
                        detail.new_baseunit = lineItem.new_baseunit;
                        detail.new_targetqtyuom = lineItem.new_targetqtyuom;
                        detail.new_division = lineItem.new_division;
                        detail.PricePerUnit = lineItem.PricePerUnit;
                        detail.new_salesunit = lineItem.new_salesunit;

                        if (detailPlant != null)
                            detail.new_plant = detailPlant.ToEntityReference();

                        detail.new_storagelocation = lineItem.new_storagelocation;

                        context.AddRelatedObject(record, new Relationship("invoice_details"), detail);
                    }
                }

                context.SaveChanges();
            }
        }
开发者ID:britehouse,项目名称:toyota-tsusho-new,代码行数:101,代码来源:OrderService.cs

示例3: 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();
        }
开发者ID:remogloor,项目名称:NServiceBus,代码行数:50,代码来源:TimeoutPersister.cs

示例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);
        }
开发者ID:remogloor,项目名称:NServiceBus,代码行数:18,代码来源:TimeoutPersister.cs

示例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();
            }
        }
开发者ID:remogloor,项目名称:NServiceBus,代码行数:50,代码来源:TimeoutPersister.cs

示例6: TryRemove

        public bool TryRemove(string timeoutId, out TimeoutData timeoutData)
        {
            timeoutData = null;

            var context = new ServiceContext(account.TableEndpoint.ToString(), account.Credentials);
            try
            {
                TimeoutDataEntity timeoutDataEntity;
                if (!TryGetTimeoutData(context, timeoutId, string.Empty, out timeoutDataEntity))
                {
                    return false;
                }

                timeoutData = new TimeoutData
                    {
                        Destination = Address.Parse(timeoutDataEntity.Destination),
                        SagaId = timeoutDataEntity.SagaId,
                        State = Download(timeoutDataEntity.StateAddress),
                        Time = timeoutDataEntity.Time,
                        CorrelationId = timeoutDataEntity.CorrelationId,
                        Id = timeoutDataEntity.RowKey,
                        OwningTimeoutManager = timeoutDataEntity.OwningTimeoutManager,
                        Headers = Deserialize(timeoutDataEntity.Headers)
                    };

                TimeoutDataEntity timeoutDataEntityBySaga;
                if (TryGetTimeoutData(context, timeoutDataEntity.SagaId.ToString(), timeoutId, out timeoutDataEntityBySaga))
                {
                    context.DeleteObject(timeoutDataEntityBySaga);
                }

                TimeoutDataEntity timeoutDataEntityByTime;
                if (TryGetTimeoutData(context, timeoutDataEntity.Time.ToString(partitionKeyScope), timeoutId, out timeoutDataEntityByTime))
                {
                    context.DeleteObject(timeoutDataEntityByTime);
                }

                RemoveState(timeoutDataEntity.StateAddress);

                context.DeleteObject(timeoutDataEntity);

                context.SaveChanges();
            }
            catch(Exception ex)
            {
                Logger.Debug(string.Format("Failed to clean up timeout {0}", timeoutId), ex);
            }

            return true;
        }
开发者ID:remogloor,项目名称:NServiceBus,代码行数:50,代码来源:TimeoutPersister.cs

示例7: RemoveTimeoutBy

        public void RemoveTimeoutBy(Guid sagaId)
        {
            var context = new ServiceContext(account.TableEndpoint.ToString(), account.Credentials);
            try
            {
                var results = (from c in context.TimeoutData
                               where c.PartitionKey == sagaId.ToString()
                               select c).ToList();

                foreach (var timeoutDataEntityBySaga in results)
                {
                    RemoveState(timeoutDataEntityBySaga.StateAddress);

                    TimeoutDataEntity timeoutDataEntityByTime;
                    if (TryGetTimeoutData(context, timeoutDataEntityBySaga.Time.ToString(partitionKeyScope), timeoutDataEntityBySaga.RowKey, out timeoutDataEntityByTime))
                        context.DeleteObject(timeoutDataEntityByTime);

                    TimeoutDataEntity timeoutDataEntity;
                    if (TryGetTimeoutData(context, timeoutDataEntityBySaga.RowKey, string.Empty, out timeoutDataEntity))
                        context.DeleteObject(timeoutDataEntity);

                    context.DeleteObject(timeoutDataEntityBySaga);
                }
                context.SaveChanges();
            }
            catch(Exception ex)
            {
                Logger.Debug(string.Format("Failed to clean up timeouts for saga {0}", sagaId), ex);
            }
        }
开发者ID:remogloor,项目名称:NServiceBus,代码行数:30,代码来源:TimeoutPersister.cs


注:本文中的ServiceContext.SaveChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。