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


C# Database.Table方法代码示例

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


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

示例1: Can_Map_Text_Column_To_Nullable_Enum

        public void Can_Map_Text_Column_To_Nullable_Enum()
        {
            var db = new Database(conn, new AttributeMappingSource().GetModel(typeof(Enum.NullableToTextColumn.Category)));

             var item = db.Table<Enum.NullableToTextColumn.Category>()
            .Single("CategoryName = {0}", Enum.CategoryEnum.Condiments.ToString());

             Assert.AreEqual(Enum.CategoryEnum.Condiments, item.CategoryName);
             Assert.AreEqual(Enum.CategoryEnum.Condiments.ToString(), item.CategoryName.ToString());
        }
开发者ID:narmontas,项目名称:DbExtensions,代码行数:10,代码来源:EnumMappingBehavior.cs

示例2: Can_Map_Numeric_Column_To_Nullable_Enum

        public void Can_Map_Numeric_Column_To_Nullable_Enum()
        {
            var db = new Database(conn, new AttributeMappingSource().GetModel(typeof(Enum.NullableToNumericColumn.Product)));

             var item = db.Table<Enum.NullableToNumericColumn.Product>()
            .First("CategoryID = {0}", Enum.CategoryEnum.Condiments);

             Assert.AreEqual(Enum.CategoryEnum.Condiments, item.CategoryID);
             Assert.AreEqual((int)Enum.CategoryEnum.Condiments, (int)item.CategoryID);
        }
开发者ID:narmontas,项目名称:DbExtensions,代码行数:10,代码来源:EnumMappingBehavior.cs

示例3: Dont_Use_Subqueries_When_Methods_Are_Called_In_Order

        public void Dont_Use_Subqueries_When_Methods_Are_Called_In_Order()
        {
            var db = new Database(MySqlConnection(), new AttributeMappingSource().GetModel(typeof(SqlTable.Product)));

             SqlSet set = db.Table<SqlTable.Product>()
            .Where("UnitsInStock > 0")
            .Skip(0)
            .Take(5);

             SqlBuilder expected = SQL
            .SELECT(db.QuoteIdentifier("Id"))
            .FROM(db.QuoteIdentifier("Product"))
            .WHERE("UnitsInStock > 0")
            .LIMIT(5)
            .OFFSET(0);

             Assert.IsTrue(SqlEquals(set, expected));
        }
开发者ID:narmontas,项目名称:DbExtensions,代码行数:18,代码来源:SqlTableBehavior.cs

示例4: Can_Persist_Enum_To_Numeric_Column

        public void Can_Persist_Enum_To_Numeric_Column()
        {
            var db = new Database(conn, new AttributeMappingSource().GetModel(typeof(Enum.ToNumericColumn.Product)));

             using (var tx = db.EnsureInTransaction()) {

            var table = db.Table<Enum.ToNumericColumn.Product>();

            var item = new Enum.ToNumericColumn.Product {
               CategoryID = Enum.CategoryEnum.Beverages,
               ProductName = ""
            };

            table.Add(item);

            Assert.AreEqual(1, table.Count("ProductID = {0} AND CategoryID = {1}", item.ProductID, item.CategoryID));

            tx.Rollback();
             }
        }
开发者ID:narmontas,项目名称:DbExtensions,代码行数:20,代码来源:EnumMappingBehavior.cs

示例5: RunTest

        public async Task RunTest()
        {
            var exists = await Database.DoesDatabaseExistsAsync(DatabaseName);

            if (!exists)
            {
                database = await Database.CreateDatabaseAsync(DatabaseName);

                database.CreateTable<SpikeDBObject>();

                var table = await database.Table<SpikeDBObject>();

                await database.SaveAsync();

                // Does this order matter
                Comics = table;
            }
            else
            {
                database = await Database.OpenDatabaseAsync(DatabaseName, true, StorageLocation.Local);

                Comics = await database.Table<SpikeDBObject>();
            }
        }
开发者ID:DavidBasarab,项目名称:FatCatComics,代码行数:24,代码来源:DatabaseTestStuff.cs

示例6: Can_Persist_Enum_To_Text_Column

        public void Can_Persist_Enum_To_Text_Column()
        {
            var db = new Database(conn, new AttributeMappingSource().GetModel(typeof(Enum.ToTextColumn.Category)));

             using (var tx = db.EnsureInTransaction()) {

            var table = db.Table<Enum.ToTextColumn.Category>();

            var item = new Enum.ToTextColumn.Category {
               CategoryName = Enum.CategoryEnum.Foo
            };

            table.Add(item);

            Assert.AreEqual(1, table.Count("CategoryID = {0} AND CategoryName = {1}", item.CategoryID, item.CategoryName.ToString()));

            item.CategoryName = Enum.CategoryEnum.Bar;

            table.Update(item);

            Assert.AreEqual(1, table.Count("CategoryID = {0} AND CategoryName = {1}", item.CategoryID, item.CategoryName.ToString()));

            tx.Rollback();
             }
        }
开发者ID:narmontas,项目名称:DbExtensions,代码行数:25,代码来源:EnumMappingBehavior.cs

示例7: GetSampleDataAsync

        private async Task GetSampleDataAsync()
        {
            if (this._groups.Count != 0)
                return;

            Database db = new Database(Database.GetDBPath());
            await db.Init();

            List<Category> lCategory = new List<Category>();

            List<Recipe> lRecipe = new List<Recipe>();

            //get collection of all categories
            AsyncTableQuery<Category> category = db.Table<Category>();
            List<Category> lCategories = await category.ToListAsync();

            for (int i = 0; i < lCategories.Count; i++)
            {
                Category c = lCategories[i];
                SampleDataGroup group = new SampleDataGroup(c.Id, c.Name);

                //get collection of all recipes for this particular category
                AsyncTableQuery<Recipe> recipe = db.Table<Recipe>().Where(a => a.Category_Id == c.Id);
                List<Recipe> lRecipes = await recipe.ToListAsync();
                lRecipes=lRecipes.OrderByDescending(a=>a.Rating).ToList();
                //iterate through each recipe in this category
                for (int k = 0; k < lRecipes.Count; k++)
                {
                    Recipe r = lRecipes[k];                    
                    group.Items.Add(new SampleDataItem(r.Id, r.Category_Id, r.Name, r.Description, r.Ingredients, r.Method, r.Image, r.Rating, r.PreparationTime));                    
                }

                this.Groups.Add(group);


            }

            /*
            Uri dataUri = new Uri("ms-appx:///DataModel/SampleData.json");

            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
            string jsonText = await FileIO.ReadTextAsync(file);
            JsonObject jsonObject = JsonObject.Parse(jsonText);
            JsonArray jsonArray = jsonObject["Groups"].GetArray();

            foreach (JsonValue groupValue in jsonArray)
            {
                JsonObject groupObject = groupValue.GetObject();
                SampleDataGroup group = new SampleDataGroup(groupObject["UniqueId"].GetString(),
                                                            groupObject["Title"].GetString(),
                                                            groupObject["Subtitle"].GetString(),
                                                            groupObject["ImagePath"].GetString(),
                                                            groupObject["Description"].GetString());

                foreach (JsonValue itemValue in groupObject["Items"].GetArray())
                {
                    JsonObject itemObject = itemValue.GetObject();
                    group.Items.Add(new SampleDataItem(itemObject["UniqueId"].GetString(),
                                                       itemObject["Title"].GetString(),
                                                       itemObject["Subtitle"].GetString(),
                                                       itemObject["ImagePath"].GetString(),
                                                       itemObject["Description"].GetString(),
                                                       itemObject["Content"].GetString()));
                }
                this.Groups.Add(group);
            }*/
        }
开发者ID:dmakhija,项目名称:DMCookBook,代码行数:67,代码来源:SampleDataSource.cs


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