services.AddDbContextFactory<CloudContext>(options => options.UseMySql(Configuration.GetConnectionString("CloudContextConnection"))); //添加Identity基架的数据库支持 services.AddDbContext<CloudContext>(options => options.UseMySql(Configuration.GetConnectionString("CloudContextConnection"))); //如果使用默认...
/// /// 输出日志/// publicstaticreadonlyILoggerFactoryloggerFactory=LoggerFactory.Create(builder=>{builder.AddConsole();});publicvoidConfigureServices(IServiceCollectionservices){//省略其他代码services.AddDbContext<TodoContext>(options=>{options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection...
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")); }); 有时候我们需要在输出EF执行的SQL语句,这便于我们调试以及优化数据库,下面的配置就把EF日志输出到控制台 /// ///输出日志 /// publicstaticreadonlyILoggerFactory loggerFactory = LoggerFactory.Create(builder => { builder.AddCo...
在界面上输入update-database。 用户注册 第一种选择是使用注册界面,这将有助于将用户添加到系统中。 public void ConfigureServices ( IServiceCollection services ) { services . AddDbContext < ApplicationDbContext >( options => options . UseSqlServer ( Configuration . GetConnectionString ( "DefaultConnectio...
option.UseConnectionString(FreeSql.DataType.Sqlite, builder.Configuration.GetConnectionString("bb")) 3. TreeItem数据实体类 新建目录Model, 新建文件Data/TreeDataFoo.cs 完整文件 using BootstrapBlazor.Components; namespace b05tree; class TreeDataFoo ...
var conStrMain = Configuration.GetConnectionString("DemoMain"); var conStrIds = Configuration.GetConnectionString("DemoIds"); //注册数据库上下文 services.AddDbContext<DemoMainDbContext>(opt => opt.UseSqlServer(conStrMain)); //注册跨域 services.AddCors(opt => ...
using Microsoft.AspNetCore.Components; namespace KeyConcepts.Client.Pages; public partial class Demo { // 在razor组件中是这样的 @inject IConfiguration config [Inject] protected IConfiguration config { get; set; }=default!; private string? GetConnectionString() { return config.GetConnectionString("...
// Add services to the container.varconnectionString = builder.Configuration.GetConnectionString("DefaultConnection"); builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(connectionString)); builder.Services.AddDatabaseDeveloperPageExceptionFilter(); buil...
Configuration.GetConnectionString("DefaultConnection");services.AddDbContext(options=>options.UseSqlServer(connectionString));ConfigureIdentityStuff(services);services.AddServerSideBlazor();services.AddScoped>();services.AddDatabaseDeveloperPageExceptionFilter();services.AddBlazorDownloadFile();services.AddScoped(...
option.UseConnectionString(FreeSql.DataType.Sqlite,builder.Configuration.GetConnectionString("bb")) 7. 数据实体类 添加BB和ORM特性到Data/WeatherForecast.cs类文件中 完整文件 usingBootstrapBlazor.Components;usingFreeSql.DataAnnotations;usingSystem.ComponentModel;namespaceb03sqlite.Data;[AutoGenerateClass(Searchable...