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


C# System.Db类代码示例

本文整理汇总了C#中System.Db的典型用法代码示例。如果您正苦于以下问题:C# Db类的具体用法?C# Db怎么用?C# Db使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Db类属于System命名空间,在下文中一共展示了Db类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Relations_Zero_One_And_One_One_Async

        public async Task Relations_Zero_One_And_One_One_Async()
        {
            var db = new Db();
            db.Initialize(TestConstants.SqlClientConnectionString, "System.Data.SqlClient");

            var result = await db.CreateCommand("select * from [dbo].[BaseTable] where [email protected]")
                .AddParameter("@id", 5)
                .ReadOneMapToAsync<BaseTable>();

            // zero one
            if (result.ZeroOneId.HasValue)
            {
                var zeroOne = await db.CreateCommand("Select * from [dbo].[ZeroOne] where [email protected]")
                  .AddParameter("@id", result.ZeroOneId)
                  .ReadOneMapToAsync<ZeroOne>();

                result.ZeroOne = zeroOne;
            }

            // one one
            var oneOne = await db.CreateCommand("Select * from [dbo].[OneOne] where [email protected]")
                .AddParameter("@id", result.OneOneId)
                .ReadOneMapToAsync<OneOne>();

            result.OneOne = oneOne;

            Assert.AreEqual(result.Name.TrimEnd(), "Base 2");
            Assert.IsTrue(result.ZeroOneId.HasValue && result.ZeroOneId == 1);
            Assert.AreEqual(result.ZeroOne.Id, 1);
            Assert.AreEqual(result.ZeroOne.Name, "Zero 1");
            Assert.AreEqual(result.OneOneId, 3);
            Assert.AreEqual(result.OneOne.Id, 3);
            Assert.AreEqual(result.OneOne.Name, "One 2");
        }
开发者ID:romagny13,项目名称:EasyDb,代码行数:34,代码来源:RelationsTests.cs

示例2: Relations_Zero_One_And_One_One

        public void Relations_Zero_One_And_One_One()
        {
            var db = new Db();
            db.Initialize(TestConstants.SqlClientConnectionString, "System.Data.SqlClient");

            var result = db.CreateCommand("select * from [dbo].[BaseTable] where [email protected]")
                .AddParameter("@id", 4)
                .ReadOneMapTo<BaseTable>();

            // zero one
            if (result.ZeroOneId.HasValue)
            {
                var zeroOne = db.CreateCommand("Select * from [dbo].[ZeroOne] where [email protected]")
                  .AddParameter("@id", result.ZeroOneId)
                  .ReadOneMapTo<ZeroOne>();

                result.ZeroOne = zeroOne;
            }

            // one one
            var oneOne = db.CreateCommand("Select * from [dbo].[OneOne] where [email protected]")
                .AddParameter("@id", result.OneOneId)
                .ReadOneMapTo<OneOne>();

            result.OneOne = oneOne;

            Assert.AreEqual(result.Name.TrimEnd(), "Base 1");
            Assert.IsFalse(result.ZeroOneId.HasValue);
            Assert.AreEqual(result.OneOneId,2);
            Assert.AreEqual(result.OneOne.Id, 2);
            Assert.AreEqual(result.OneOne.Name, "One 1");
        }
开发者ID:romagny13,项目名称:EasyDb,代码行数:32,代码来源:RelationsTests.cs

示例3: Merge

 public static void Merge(string path, Db to_db)
 {
     Log.Warning ("Will merge db {0} into main f-spot db {1}", path, FSpot.Global.BaseDirectory + "/photos.db" );
     Db from_db = new Db ();
     from_db.Init (path, true);
     //MergeDb mdb = new MergeDb (from_db, to_db);
 }
开发者ID:iainlane,项目名称:f-spot,代码行数:7,代码来源:MergeDb.cs

示例4: getHtmlAsync

        /// <summary>
        /// Get html Async
        /// </summary>
        private string getHtmlAsync(string url, string customUserAgent, Db.HttpHeadersInfoCollection httpHeaders)
        {
            try
            {

                //set new proxy if use proxy
                CookieAwareWebClient client = Factory.Instance.getWebClientNext(customUserAgent,httpHeaders);
                client = setCredential(client, url);              

                //Set Wait time
                System.Threading.Thread.Sleep(Factory.Instance.i.Project.ScrapingSetting.waitEachRequestMilliseconds);

                //Stream s = 
                asyncEnd = false;
                client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);               
                client.OpenReadAsync(new Uri(url));
                while (asyncEnd == false)
                    System.Threading.Thread.Sleep(10);
              
                return this.currentHtml;

            }
            catch (Exception ex)
            {
                //Wait after error - prevent next request
                System.Threading.Thread.Sleep(Factory.Instance.i.Project.ScrapingSetting.waitAfterError);
                Factory.Instance.log.Error(ex);
                return string.Empty;
            }
        }
开发者ID:kantone,项目名称:intelliscraper,代码行数:33,代码来源:HttpUtils.cs

示例5: Send

		public static async Task Send(Db db)
		{
			var host = HttpContext.Current?.Request.ServerVariables["HTTP_HOST"];
            if (host == null || !host.Equals("jeegoordah.azurewebsites.net", StringComparison.InvariantCultureIgnoreCase))
			{
				throw new Exception($"Sending notifications is disabled for {host}");
			}

			var sendTasks = db.Query<Bro>()
				.Where(x => x.Email != null)
				.Where(x => x.Notifications.Count > 0)
				.ToArray()
				.Select(async bro =>
				{
					var message = new SendGridMessage
					{
						From = _from,
						To = new[] {new MailAddress(bro.Email)},
						Subject = "Jeegoordah notifications",
						Text = GetContent(bro.Notifications),
						Html = null,
					};

					_logger.I($"Sending {bro.Notifications.Count} notifications for {bro.Name}");
					await _transport.DeliverAsync(message);
					_logger.I($"Notifications for {bro.Name} sent");
				});

			await Task.WhenAll(sendTasks);

			db.Query<Notification>().ForEach(db.Session.Delete);
			_logger.I("Notifications deleted");
		}
开发者ID:kruglik-alexey,项目名称:jeegoordah,代码行数:33,代码来源:NotificationsSender.cs

示例6: ShouldPropagateFieldsFromAllBaseTemplates

    public void ShouldPropagateFieldsFromAllBaseTemplates()
    {
      // arrange
      ID myTemplateId = ID.NewID;

      using (var db = new Db
      {
        this.baseTemplateOne,
        this.baseTemplateTwo,
        this.baseTemplateThree,
        new DbTemplate("Main Template", myTemplateId) {BaseIDs = new[] {this.baseTemplateOne.ID, this.baseTemplateThree.ID}},
        new DbItem("home", ID.NewID, myTemplateId)
      })
      {
        // act
        Item home = db.GetItem("/sitecore/content/home");
        Template template = TemplateManager.GetTemplate(myTemplateId, db.Database);

        // assert

        // note: as noted above, fields propagation should "just" work
        home.Fields["Title"].Should().NotBeNull("home.Fields[\"Title\"]");
        home.Fields["Description"].Should().NotBeNull("home.Fields[\"Description\"]");

        template.GetField("Title").Should().NotBeNull("template.GetField(\"Title\")");
        template.GetField("Description").Should().NotBeNull("template.GetField(\"Description\")");
      }
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:28,代码来源:DbTemplateInheritanceTest.cs

示例7: CameraFileSelectionDialog

		public CameraFileSelectionDialog (GPhotoCamera cam, Db datab)
		{
			camera = cam;
			db = datab;
			saved_files = null;
			selected_tags = null;
		}
开发者ID:guadalinex-archive,项目名称:guadalinex-v6,代码行数:7,代码来源:CameraFileSelectionDialog.cs

示例8: HistoryPresenter

        public HistoryPresenter(Db db)
        {
            this.db = db;

            nullAccount = new Account();
            nullAccount.Name = "";
        }
开发者ID:qwer,项目名称:budget,代码行数:7,代码来源:HistoryPresenter.cs

示例9: Save

        public async Task<int> Save(long routeId, Station station, int number)
        {
            if(routeId <= 0) throw new ArgumentException("routeId <= 0");
            if(station == null) throw new ArgumentNullException("station");

            using (var db = new Db())
            {
                using (var transaction = db.Database.BeginTransaction(IsolationLevel.RepeatableRead))
                {
                    try
                    {
                        var route = db.Routes.SingleOrDefault(s => s.Id == routeId);
                        if(route == null) throw new NullReferenceException("route");

                        station = await _stationRepository.GetByLatLng(station.Latitude, station.Longitude);
                        if(station == null) throw new NullReferenceException("station");

                        var routeStation = new RouteStation(){Number = number,RouteId = routeId,StationId = station.Id};
                        db.Entry(routeStation).State = EntityState.Added;
                        return await db.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        Log.Error(ex.Message);
                        throw;
                    }
                }
            }

        }
开发者ID:Dorskiy,项目名称:RouterWebAppSharp,代码行数:31,代码来源:IRouteStationRepository.cs

示例10: getHtml

        /// <summary>
        /// Get html
        /// </summary
        private static string getHtml(string url, string customUserAgent, Db.HttpHeadersInfoCollection httpHeaders)
        {
            try
            {

                //set new proxy if use proxy
                CookieAwareWebClient client = Factory.Instance.getWebClientNext(customUserAgent,httpHeaders);
                client = setCredential(client, url);

                //Set Wait time
                System.Threading.Thread.Sleep(Factory.Instance.i.Project.ScrapingSetting.waitEachRequestMilliseconds);


                Stream s = client.OpenRead(url); ;
                StreamReader sr = new StreamReader(s);
                string html = sr.ReadToEnd();
                s.Close();
                return html;
            }
            catch (Exception ex)
            {
                //Wait after error - prevent next request
                System.Threading.Thread.Sleep(Factory.Instance.i.Project.ScrapingSetting.waitAfterError);
                Factory.Instance.log.Error(ex);
                return string.Empty;
            }
        }
开发者ID:kantone,项目名称:intelliscraper,代码行数:30,代码来源:HttpUtils.cs

示例11: Run

        public void Run()
        {
            _Console.WriteLine("End statement with ';'");
            _Console.WriteLine("Enter 'quit' when done");
            _Console.WriteLine();

            string line;
            string statement = "";
            _Console.Write(">");
            while((line = _Console.ReadLine()) != "quit") {
                statement += line + '\n';
                if(!line.Trim().EndsWith(";"))
                    continue;

                using(var db = new Db()) {
                    try {
                        db.ExecuteReader(statement, PrintHeader,PrintGrid);
                    } catch(Exception e) {
                        _Console.WriteLine(e.Message);
                    }
                }
                statement = "";
                _Console.Write(">");
            }
        }
开发者ID:vchekan,项目名称:CodeQL,代码行数:25,代码来源:CodeConsole.cs

示例12: HttpDataHandler

		public HttpDataHandler(HttpRequest request, Db db)
		{
			string cmd = request.Form["ex"];
			Form = request.Form;
			Database = db;
			Nodes = new Node();
			if (!string.IsNullOrEmpty(cmd))
			{
				if (cmd.Equals("insert"))
				{
					ParseInsertQuery();
				}
				else if (cmd.Equals("update"))
				{
					ParseUpdateQuery();
				}
				else if (cmd.Equals("delete"))
				{
					ParseDeleteQuery();
				}
				else if (cmd.Equals("select"))
				{
					ParseSelectQuery();
				}
			}
		}
开发者ID:mind0n,项目名称:hive,代码行数:26,代码来源:HttpExecute.cs

示例13: ShouldBeThreadLocalStandardValuesProvider

    public void ShouldBeThreadLocalStandardValuesProvider()
    {
      var templateId = ID.NewID;
      var itemId = ID.NewID;
      var fieldId = ID.NewID;

      var t1 = Task.Factory.StartNew(() =>
      {
        using (var db = new Db
                          {
                            new DbTemplate(templateId) { { fieldId, "$name" } },
                            new DbItem("Home", itemId, templateId)
                          })
        {
          Thread.Sleep(1000);
          db.GetItem(itemId)[fieldId].Should().Be("Home");
        }
      });

      var t2 = Task.Factory.StartNew(() =>
      {
        using (var db = new Db
                          {
                            new DbTemplate(templateId) { fieldId },
                            new DbItem("Home", itemId, templateId)
                          })
        {
          db.GetItem(itemId)[fieldId].Should().BeEmpty();
        }
      });

      t1.Wait();
      t2.Wait();
    }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.FakeDb,代码行数:34,代码来源:DbConcurrencyTest.cs

示例14: FieldBase

        public FieldBase(Db.Field Field)
        {
            this.TenantID = Configure.GetTenantResolutionProvider().GetTenantID();

            if (this.TenantID != Field.TenantID)
            {
                Log.Fatal("TenantID Does not match. FieldID: {0}, Global TenantID: {1}, Field TenantID: {2}",
                    Field.FieldID, this.TenantID, Field.TenantID);
                throw new FatalException("Data error.");
            }

            this.Dirty = false;
            this.FieldID = Field.FieldID;

            this.ValueString = Field.ValueText;
            this.ValueDate = Field.ValueDate;
            this.ValueDecimal = Field.ValueDecimal;
            this.ValueBool = Field.ValueBoolean;
            this.ValueLookup = Field.ValueLookup;
            this.ValueBinary = Field.ValueBinary;
            this.ValueEntityReference = Field.ValueEntityReference;
            this.ValueItemReference = Field.ValueItemReference;
            this.Guid = Field.Guid;

            RefreshOriginalValues();
        }
开发者ID:emisaacson,项目名称:EffectFramework,代码行数:26,代码来源:FieldBase.cs

示例15: ShouldPropagateFieldsFromTheBaseTemplate

    public void ShouldPropagateFieldsFromTheBaseTemplate()
    {
      // arrange
      ID templateId = ID.NewID;

      using (var db = new Db
      {
        this.baseTemplateOne,
        new DbTemplate("My Template", templateId) {BaseIDs = new[] {this.baseTemplateOne.ID}},
        new DbItem("home", ID.NewID, templateId)
      })
      {
        // act
        Item home = db.GetItem("/sitecore/content/home");
        Template template = TemplateManager.GetTemplate(templateId, db.Database);
        Template baseTemplate = TemplateManager.GetTemplate(this.baseTemplateOne.ID, db.Database);

        TemplateField titleField = baseTemplate.GetField("Title");

        // assert 

        // note: it should "just" work as Sitecore wil do all the looking up the templates chain
        template.GetFields(false).Should().NotContain(f => f.Name == "Title" || f.ID == titleField.ID);
        template.GetFields(true).Should().Contain(f => f.Name == "Title" && f.ID == titleField.ID);

        template.GetField("Title").Should().NotBeNull("template.GetField(\"Title\")");
        template.GetField(titleField.ID).Should().NotBeNull("template.GetField(titleField.ID)");

        home.Fields["Title"].Should().NotBeNull("home.Fields[\"Title\"]");
        home.Fields[titleField.ID].Should().NotBeNull("home.Fields[titleField.ID]");
      }
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:32,代码来源:DbTemplateInheritanceTest.cs


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