mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-19 16:06:36 +08:00
种子数据
This commit is contained in:
24
Yi.Framework/Yi.Framework.Model/DbInit/DataSeed.cs
Normal file
24
Yi.Framework/Yi.Framework.Model/DbInit/DataSeed.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Model.DbInit
|
||||
{
|
||||
public class DataSeed
|
||||
{
|
||||
public async static Task SeedAsync(DbContext _Db)
|
||||
{
|
||||
if (!_Db.Set<user>().Any())
|
||||
{
|
||||
await _Db.Set<user>().AddAsync(new user { username = "admin", password = "123" });
|
||||
}
|
||||
await _Db.SaveChangesAsync();
|
||||
|
||||
Console.WriteLine(nameof(DbContext) + ":数据库用户初始成功!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user