我们如何将参数传递给 dotnet ef 数据库更新?
我希望能够使用参数更新不同的数据库。
我试过了
dotnet ef 数据库更新“接受”
dotnet ef 数据库更新 接受
但它没有用..
或者我如何放置一个开关以从我的配置中获取不同的 conenctionString ?
public ProjectContext CreateDbContext(string[] args)
{
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
// Find a way to get different connection string
var connectionString = configuration.GetConnectionString(args[0]);
var builder = new DbContextOptionsBuilder<ProjectContext >();
builder.UseSqlServer(connectionString);
return new ProjectContext(builder.Options);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试控制我们可以输入带有标签和分数的多个玩家.
但是当我们单击我的AddPlayer按钮时,我创建了一个播放器,然后我需要将表单控件值重置为默认值.
我已经尝试了很多东西,但没有任何作用....它永远不会改变视图值.
这是代码:
addPlayer(form: ControlGroup) {
var player = new Player();
player.tag = form.value.tag;
player.name = form.value.name;
player.score = form.value.score;
// nothing work
form.value = null;
form.value.tag = null;
form.value.tag = '';
this.playerService.addPlayer(player.tag, player.name, player.score);
this.newplayer.next(player);
}
Run Code Online (Sandbox Code Playgroud)
这是html
<form (submit)="addPlayer(playerForm)" [ng-form-model]="playerForm">
<div class="form-group" [class.has-error]="!playerForm.find('tag').valid && playerForm.find('tag').touched">
<div class="col-md-3 text-right">
<label for="tag">Tag: </label>
</div>
<input type="text" id="tag" #tag="form" [ng-form-control]="playerForm.controls['tag']" placeholder="Tag"/>
<span *ng-if="tag.control.hasError('required') && !tag.control.pristine">Tag is required</span>
</div>
<div class="form-group" [class.has-error]="!playerForm.find('name').valid && playerForm.find('name').touched">
<div class="col-md-3 text-right">
<label for="name">Player Name: </label>
</div> …Run Code Online (Sandbox Code Playgroud) 试图在我的 angular2 应用程序中创建我的重定向路由。
但我的问题是,当有人输入像“nopath”这样的无效路径时,用户会被重定向到“HomeComponent”,但 url 仍然保留“/#/nopath”
我也希望 redirectTo 路由更改 url!我应该如何实现这一目标?
我应该在我的 HomeComponent 构造函数中放置一个 if 来检查当前 url 并将他的路由更改为 homecomponent 吗?还是我遗漏了什么?
路线:
const routes: Routes = [
{ path: '', pathMatch: 'full', component: HomeComponent },
{ path: 'login', component: LoginComponent, canActivate: [AnonymousGuard] },
{ path: 'register', component: RegisterComponent, canActivate: [AnonymousGuard] },
{ path: 'users', component: UserComponent, canActivate: [AuthGuard] },
{ path: '**', redirectTo: '' }
];
export const routing: ModuleWithProviders = RouterModule.forRoot(routes, {useHash: true});
Run Code Online (Sandbox Code Playgroud)
编辑:
试过了,但我没有重定向到 home 组件
const routes: Routes = …Run Code Online (Sandbox Code Playgroud) 我正在尝试为日期输入创建一个验证器。
所以我已经写了这段代码,但是没有按预期工作!
export class CustomValidators {
static dateMinimum(date: string): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
if (control.value == null) {
return null;
}
const controlDate = moment(control.value, FORMAT_DATE);
if (!controlDate.isValid()) {
return null;
}
const validationDate = moment(date);
return controlDate.isAfter(validationDate) ? null : {
'date-minimum': {
'date-minimum': validationDate.format(FORMAT_DATE),
'actual': controlDate.format(FORMAT_DATE)
}
};
};
}
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
ERROR Error: Expected validator to return Promise or Observable.at toObservable (forms.js:749)
Run Code Online (Sandbox Code Playgroud)
我真的不知道哪件事是不正确的...我发现了很多示例,这些示例如何创建不带参数但不带参数的自定义验证器...
我需要像这样使用验证器:
this.projectForm = this.builder.group({
date: ['', Validators.required, CustomValidators.dateMinimum('2018-12-12')], …Run Code Online (Sandbox Code Playgroud) 我正在尝试映射 httpclient 的结果,我们需要使用 RxJs 的新导入来使 treeshaking 工作。
所以我找到了 2 张地图,但都没有用...
import { map } from 'rxjs/operator/map';
import { map } from 'rxjs/operators/map';
Run Code Online (Sandbox Code Playgroud)
我们需要删除的旧时尚方式
import 'rxjs/add/operator/map';
Run Code Online (Sandbox Code Playgroud)
这是我开始工作所需的代码!
getValues(): Observable<Value[]> {
return this.http.get<Response<Values>>(this.url).map(reponse => {
return reponse.data.values;
});
}
Run Code Online (Sandbox Code Playgroud)
但 .map 并不以可观察性而闻名,
我正在尝试检查JWT令牌的到期日期,而我尝试执行的所有操作均未获得正确的日期。
"exp": 1522210228 => real answer => Wednesday, March 28, 2018 12:10:28 AM
Run Code Online (Sandbox Code Playgroud)
我尝试过那些libs,但没有使它们起作用...
const helper = new JwtHelperService();
const decodedToken = helper.decodeToken(this.authentificationInfos.token);
const expirationDate = helper.getTokenExpirationDate(this.authentificationInfos.token);
console.log(expirationDate); => null?
Run Code Online (Sandbox Code Playgroud)
import * as decode from 'jwt-decode';
const token = decode<{ data: { exp: number, iat: number, iss: string, nbf: number, username: string } }>(this.authentificationInfos.token);
const date = new Date(token.data.exp);
console.log(date); => Sun Jan 18 1970 09:50:10 GMT-0500 (Eastern Standard Time)
const d = new Date(0);
d.setUTCMilliseconds(token.data.exp); …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 VSTS(Azure DevOps)到 Azure WebApp 的帮助下为 Github 上的项目创建 CI/CD 管道。
我正处于该过程的开始阶段,并且一直坚持让我的项目直接在 VSTS 中构建。
后端项目为DotNetCore项目,前端尚未确定。
我在 github 上的存储库看起来像这样
/
-> Project.FrondEnd
-> Project.BackEnd
-> Documents
-> .gitignore
-> readme.md
Run Code Online (Sandbox Code Playgroud)
在文件夹 Project.BackEnd 中,它将如下所示:
/Project.BackEnd
-> Project.Api (Entry point of the server app)
-> Project.Entities
-> Project.DataAccess
-> Project.Services
-> Project.sln
Run Code Online (Sandbox Code Playgroud)
当我在 VSTS 上配置管道时,我需要编写 pipeline.yml 文件,但似乎我缺少一些关于如何指向我的服务器入口点以便它可以构建项目的知识!
这是我的 yml 文件
trigger:
- master
pool:
vmImage: 'vs2017-win2016'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
Run Code Online (Sandbox Code Playgroud)
这样它就行不通了,我收到了这条消息:
错误 MSB1003:指定项目或解决方案文件。当前工作目录不包含项目或解决方案文件。
我试图将步骤更改为这样的 …
angular ×4
.net-core ×1
angular5 ×1
azure-devops ×1
javascript ×1
jwt ×1
rxjs5 ×1
typescript ×1