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


C# Data.SaveChanges方法代码示例

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


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

示例1: SeedNewsData

 static void SeedNewsData(Data.NewsDB context)
 {
     context.News.AddRange(new[] {
         new News("Митьо очите се прекръсти на Митьо Мехура"),
         new News("Шведи откриват смисълът на живота, масони ги колят"),
         new News("Германски крайно-десни формации на лов за емигранти"),
         new News("Азис с нов клип в МТВ (Междугалактическа ТелеВизия)"),
         new News("Путин ще представя Русия на Евровизия 2017"),
         });
     context.SaveChanges();
 }
开发者ID:AsenTahchiyski,项目名称:SoftUni,代码行数:11,代码来源:NewsDBMain.cs

示例2: UpdateNewsContent

        static void UpdateNewsContent(Data.NewsDB context)
        {
            Console.Write("Enter id of the news you want to update: ");
            int id = int.Parse(Console.ReadLine());
            Console.Write("Enter new content: ");
            string newContent = Console.ReadLine();
            News newsToEdit = null;
            try
            {
                newsToEdit = context.News
                .Where(n => n.Id == id)
                .First();
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("News with id {0} not found.", id);
                return;
            }

            newsToEdit.Content = newContent;
            context.SaveChanges();
            Console.WriteLine("News ID {0} updated successfully.", id);
        }
开发者ID:AsenTahchiyski,项目名称:SoftUni,代码行数:23,代码来源:NewsDBMain.cs

示例3: processResponsesFromDataScope

    protected override void processResponsesFromDataScope(Data.SymmetryEntities dc_, Data.MarketSnap saveToThisSnap_, string marketSnapCode_)
    {
      OutputToCSV(m_resultsFromDataScope);

      if (m_resultsFromDataScope == null) return;

      var config = BondDiscoveryConfig.GetInstance();

      foreach (var response in m_resultsFromDataScope)
      {
        foreach (var row in response.Rows)
        {
          try
          {
            var isin = GetValueFromObjectArray<string>((int)FieldsToReturn.InstrumentID, row, ThrowBehavior.Throw);
            var ric = GetValueFromObjectArray<string>((int)FieldsToReturn.TradewebRIC, row, ThrowBehavior.DontThrow);
            var maturity = GetValueFromObjectArray<DateTime>((int)FieldsToReturn.Maturity, row, ThrowBehavior.Throw);
            var description = GetValueFromObjectArray<string>((int)FieldsToReturn.Description, row, ThrowBehavior.Throw);
            var currency = GetValueFromObjectArray<string>((int)FieldsToReturn.Currency, row, ThrowBehavior.DontThrow);
            var coupon = GetValueFromObjectArray<double>((int)FieldsToReturn.Coupon, row, ThrowBehavior.Throw);
            var auctionDate = GetValueFromObjectArray<DateTime?>((int)FieldsToReturn.AuctionDate, row, ThrowBehavior.DontThrow);
            var effectiveDate = GetValueFromObjectArray<DateTime?>((int)FieldsToReturn.EffectiveDate, row, ThrowBehavior.DontThrow);
            var firstCouponDate = GetValueFromObjectArray<DateTime?>((int)FieldsToReturn.FirstCouponDate, row, ThrowBehavior.DontThrow);
            var issueDate = GetValueFromObjectArray<DateTime?>((int)FieldsToReturn.IssueDate, row, ThrowBehavior.DontThrow);
            var series = GetValueFromObjectArray<string>((int)FieldsToReturn.Series, row, ThrowBehavior.DontThrow);
            var term = GetValueFromObjectArray<int?>((int)FieldsToReturn.Term, row, ThrowBehavior.DontThrow);
            var assetSubType = GetValueFromObjectArray<string>((int)FieldsToReturn.AssetSubType,row,ThrowBehavior.DontThrow);
            var couponClass = GetValueFromObjectArray<string>((int) FieldsToReturn.CouponClassCode, row, ThrowBehavior.DontThrow);
            var countryCode = GetValueFromObjectArray<string>((int) FieldsToReturn.CountryCode, row, ThrowBehavior.DontThrow);
            var inflationFlag = GetValueFromObjectArray<string>((int)FieldsToReturn.InflationProtectedFlag,row,ThrowBehavior.DontThrow);
            var floaterFlag = GetValueFromObjectArray<string>((int)FieldsToReturn.FloaterFlag,row,ThrowBehavior.DontThrow);

            FIChangeTracking.DisableChangeTracking(ref dc_);

            try
            {
              SLog.log.DebugFormat("Adding new bond to database with ISIN={0}", isin);

              // create instrument
              var fi = new FI
              {
                InstrumentType = InstrumentType.Bond,
                Currency = currency,
                DisplayName = description,
                Maturity = maturity,
                SymmetryCode = isin
              };
              dc_.FIs.Add(fi);

              dc_.SaveChanges();

              FIBondHelpers.SetOrUpdateIdentifier(fi, IdentifierType.ISIN, isin, dc_);
              FIBondHelpers.SetOrUpdateIdentifier(fi, IdentifierType.RIC, ric, dc_);
              FIBondHelpers.SetOrUpdateIdentifier(fi, IdentifierType.Bloomberg, string.Format("{0} Govt", isin), dc_);
              dc_.SaveChanges();

              // create bond
              var fiBond = new FIBond
              {
                FIID = fi.FIID,
                Coupon = Convert.ToDecimal(coupon),
                EffectiveDate = effectiveDate,
                FirstCouponDate = firstCouponDate,
                AuctionDate = auctionDate,
                IssueDate = issueDate,
                Series = series,
                Term = term,
                Market = config == null ? assetSubType : config.GetMarket(countryCode, assetSubType),
                IsFloater=floaterFlag!=null && String.Compare("Y", floaterFlag, StringComparison.OrdinalIgnoreCase)==0 ? 1 : 0,
                IsInflationLinked = inflationFlag!=null && String.Compare("Y", inflationFlag, StringComparison.OrdinalIgnoreCase)==0 ? 1 : 0,
              };
              dc_.FIBonds.Add(fiBond);
              dc_.SaveChanges();
            }
            finally
            {
              FIChangeTracking.EnableChangeTracking(ref dc_);
            }

          }
          catch
          {
            continue; // a required value wasn't found
          }



        } // end inner for
      } // end first for

    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:91,代码来源:DSInstrumentAdderBond.cs


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