标签:syn oda net entity res ted return 组件 dir
menus = await Mmservise.GetMenuAsync(DateTime.Now);
public class MenuService { public Task< List<Menu> > GetMenuAsync(DateTime startDate) { List<Menu> meuns = new List<Menu>(); string[] days = new string[] { "2021-02-06", "2021-02-07", "2021-02-08" }; var rng = new Random(); foreach (string daystr in days) { Menu a = new Menu { ID = Guid.NewGuid(), Name = "红烧鱼", MenuDay = Convert.ToDateTime(daystr), DefaultNamber = 1, Price = rng.Next(5, 30), Type = "午餐" }; Menu b = new Menu { ID = Guid.NewGuid(), Name = "大盘鸡", MenuDay = Convert.ToDateTime(daystr), DefaultNamber = 1, Price = rng.Next(5, 30), Type = "午餐" }; Menu c = new Menu { ID = Guid.NewGuid(), Name = "烤肉", MenuDay = Convert.ToDateTime(daystr), DefaultNamber = 1, Price = rng.Next(5, 30), Type = "午餐" }; Menu d = new Menu { ID = Guid.NewGuid(), Name = "油条豆浆", MenuDay = Convert.ToDateTime(daystr), DefaultNamber = 1, Price = rng.Next(5, 30), Type = "早餐" }; Menu e = new Menu { ID = Guid.NewGuid(), Name = "炸酱面", MenuDay = Convert.ToDateTime(daystr), DefaultNamber = 1, Price = rng.Next(5, 30), Type = "晚餐" }; meuns.Add(a); meuns.Add(b); meuns.Add(c); meuns.Add(d); meuns.Add(e); } return Task.FromResult(meuns); } }
public class BlazorApp0206Context: DbContext { public DbSet<Menu> Menus { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseSqlite("Data Source=BlazorApp0206.db"); }
Install-Package Microsoft.EntityFrameworkCore.Tools Add-Migration InitialCreate0209 Update-Database
public class MenuService { public Task< List<Menu> > GetMenuAsync(DateTime startDate) { using (var db = new BlazorApp0206Context()) { var meuns = db.Menus.ToList<Menu>(); return Task.FromResult(meuns); } } } }
在Blazor Server 项目中使用 EF Core Sqlite
标签:syn oda net entity res ted return 组件 dir
原文地址:https://www.cnblogs.com/kqw/p/14394564.html