Example #1
0
        private static async Task UpdateNewCategoryAsync(decimal categoryId)
        {
            using var db = new ExampleDataContext();
            await db.Categories
            .Where(c => c.CategoryID == categoryId)
            .Set(c => c.CategoryName, c => c.CategoryName + "!")
            .UpdateAsync();

            Console.WriteLine("Category updated: Identity = " + categoryId);
        }
Example #2
0
    //<Snippet2>
    protected void LinqDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
        ExampleDataContext exampleContext = new ExampleDataContext();

        e.Result = from p in exampleContext.Products
                   where p.Category == "Beverages"
                   select new {
            ID   = p.ProductID,
            Name = p.Name
        };
    }
Example #3
0
        private static async Task ReadScalarAsync()
        {
            using var db = new ExampleDataContext();
            var q =
                from c in db.Categories
                orderby c.CategoryID descending
                select new
            {
                Id   = c.CategoryID,
                Name = c.CategoryName
            };

            var row = await q.FirstAsync();

            Console.WriteLine("Category read: " + row.Id + " : " + row.Name);
        }
Example #4
0
        private static async Task <decimal> InsertNewCategoryAsync()
        {
            using var db = new ExampleDataContext();
            var cat = new Category
            {
                CategoryName = "MyCat " + DateTime.Now.ToString("HH:mm:ss"),
                Description  = "MyCat Description",
                Picture      = null
            };

            var identity = (decimal)await db.InsertWithIdentityAsync(cat);

            Console.WriteLine("Category added: " + cat.CategoryName + ", Identity = " + identity);

            return(identity);
        }
Example #5
0
        private static async Task ReadCollectionAsync()
        {
            using var db = new ExampleDataContext();
            var q =
                from c in db.Categories
                from p in db.Products.Where(p => p.CategoryID == c.CategoryID).DefaultIfEmpty()
                orderby c.CategoryID descending
                select new
            {
                ProductName  = p.ProductName,
                CategoryName = c.CategoryName
            };

            Console.WriteLine("All categories:");

            foreach (var c in await q.ToListAsync())
            {
                Console.WriteLine(c.CategoryName + " : " + (c.ProductName ?? "null"));
            }
        }
 public PeopleController()
 {
     Database = new ExampleDataContext();
 }