我有这个枚举(我正在使用TypeScript):
export enum CountryCodeEnum {
France = 1,
Belgium = 2
}
Run Code Online (Sandbox Code Playgroud)
我想在我的表单中构建一个select,每个选项的枚举整数值为value,枚举文本为label,如下所示:
<select>
<option value="1">France</option>
<option value="2">Belgium</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点 ?
默认情况下,ASP.NET Core Identity的密码策略至少需要一个特殊字符,一个大写字母,一个数字,......
我该如何更改此限制?
文档中没有任何内容(https://docs.asp.net/en/latest/security/authentication/identity.html)
我尝试覆盖Identity的用户管理器,但我没有看到哪个方法管理密码策略.
public class ApplicationUserManager : UserManager<ApplicationUser>
{
public ApplicationUserManager(
DbContextOptions<SecurityDbContext> options,
IServiceProvider services,
IHttpContextAccessor contextAccessor,
ILogger<UserManager<ApplicationUser>> logger)
: base(
new UserStore<ApplicationUser>(new SecurityDbContext(contextAccessor)),
new CustomOptions(),
new PasswordHasher<ApplicationUser>(),
new UserValidator<ApplicationUser>[] { new UserValidator<ApplicationUser>() },
new PasswordValidator[] { new PasswordValidator() },
new UpperInvariantLookupNormalizer(),
new IdentityErrorDescriber(),
services,
logger
// , contextAccessor
)
{
}
public class PasswordValidator : IPasswordValidator<ApplicationUser>
{
public Task<IdentityResult> ValidateAsync(UserManager<ApplicationUser> manager, ApplicationUser user, string password)
{
return Task.Run(() =>
{
if (password.Length >= 4) …
Run Code Online (Sandbox Code Playgroud) 如何使用TypeScipt解析复杂的json对象?
我有一个客户对象,他有一些发票.
这是我的模特:
export class Customer {
public id: string;
public name: string;
public invoices: CustomerInvoice[];
get invoicesCount(): number {
if (this.invoices== null) {
return 0;
}
return this.invoices.length;
}
constructor() {
}
}
export class CustomerInvoice {
public id: number;
constructor() {
}
}
Run Code Online (Sandbox Code Playgroud)
在我的服务中,我有:
ngOnInit() {
if (this.id != null) {
this.dataService.getCustomer(this.id).subscribe(data => {
this.customer = data;
},
err => console.log(err));
}
}
Run Code Online (Sandbox Code Playgroud)
客户数据很棒(我的客户ID,名称等都有一些值)但发票是空的.
json是正确的,data.Invoices.length返回一个数字.
我按照以下说明在Visual Studio 2015中创建了一个新的.NET Core项目:https://www.microsoft.com/net/core#windowsvs2015
它工作正常,我可以添加断点等没问题.
然后我运行Tools-> NuGet Package Manager-> Manage NuGet Packages for Solution ...
我可以选择将Microsoft.NETCore.App更新到最新的稳定版本v1.1.0.
我得到的第一个问题是错误:
无法找到与其中一个目标运行时兼容的框架'.NETCoreApp,Version = v1.0'的运行时目标:'win10-x64,win81-x64,win8-x64,win7-x64'.
这似乎是由于更新了从project.json删除行,所以我添加了缺少的行并将版本更改为1.1.0,所以我的project.json现在看起来像这样:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
Run Code Online (Sandbox Code Playgroud)
程序然后构建没有问题,但当我运行程序时,我得到错误:
程序'[13048] dotnet.exe'已退出,代码为-2147450749(0x80008083).
有任何想法吗?
这个问题使我发疯...
我有这个代码:
if (control.value==null||control.value == "" || control.value == " " || control.value.length != 5) {
// do something
}
Run Code Online (Sandbox Code Playgroud)
我的问题:control.value.length
总是返回“未定义”。
我尝试使用像这样的字符串变量,但结果是相同的。
var curVal: string = control.value;
if (curVal==null||curVal== "" || curVal == " " || curVal != 5) {
// do something
}
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
编辑:精度:我的control.value不为null或为空,我测试值为59000
此代码:
console.log(control.value + ' - ' + control.value.length);
Run Code Online (Sandbox Code Playgroud)
记录此:59000-未定义
编辑2:谢谢你,解决了。问题是我的control.value是数字而不是字符串。
编辑(02/03/2018):自实体框架核心2.1以来,EF Core实现了事务,跨上下文事务,环境事务和事务范围,因此这个问题现在已经过时了.
这是关于EF Core中交易的官方文档:https://docs.microsoft.com/en-us/ef/core/saving/transactions.
如何在不同的方法中使用相同的事务?目标是在发生错误时提交或回滚所有修改.
我正在使用Entity Framework Core版本1.1.0-preview1-final和SQL Server 2014.
例如,我有一个Entity Framework数据库上下文:
public class ApplicationDatabaseContext : DbContext
{
public ApplicationDatabaseContext(DbContextOptions<ApplicationDatabaseContext> options)
: base(options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TransactionLog1>(entity =>
{
entity.ToTable("TRANSACTION_LOG_1");
entity.Property(e => e.CreationDate)
.HasColumnType("datetime")
.HasDefaultValueSql("getdate()");
});
modelBuilder.Entity<TransactionLog2>(entity =>
{
entity.ToTable("TRANSACTION_LOG_2");
entity.Property(e => e.CreationDate)
.HasColumnType("datetime")
.HasDefaultValueSql("getdate()");
});
}
public virtual DbSet<TransactionLog1> TransactionLog1 { get; set; }
public virtual DbSet<TransactionLog2> TransactionLog2 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有两个类来处理数据,两者都使用相同的上下文:
public interface …
Run Code Online (Sandbox Code Playgroud) c# transactions sql-server-2014-express entity-framework-core asp.net-core-1.0
在ASP.NET Core之前,我曾经实现过这样的计时器:
public class Class1
{
Timer tm = null;
public Class1()
{
this.tm.Elapsed += new ElapsedEventHandler(Timer_Elapsed);
this.tm.AutoReset = true;
this.tm = new Timer(60000);
}
protected void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
this.tm.Stop();
try
{
// My business logic here
}
catch (Exception)
{
throw;
}
finally
{
this.tm.Start();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我对.NETCoreApp1.1控制台应用程序有同样的需求,并且System.Timers不再存在于ASP.NET Core中.我也尝试使用System.Threading.Timer,但项目不再构建.
如何使用.NETCoreApp1.1实现Timer?是否有相当于System.Timers?
我有一个表单来更新客户对象.
我有一个客户类型的选择,我想在获得客户数据时预先选择当前值.我怎样才能做到这一点 ?
这是我的html表单的一部分:
<div class="form-group">
<label for="type" class="req">Type</label>
<select class="form-control" ngControl="type">
<option *ngFor="#p of typecustomerlist" [value]="p.code">{{p.label}}</option>
</select>
<div [hidden]="type.valid" class="alert alert-danger">
Please select a type
</div>
</div>
<div class="form-group">
<label for="lastname" class="req">Last name</label>
<input type="text" ngControl="lastname" value="{{customer.Lastname}}" />
<div *ngIf="lastname.dirty && !lastname.valid" class="alert alert-danger">
<p *ngIf="lastname.errors.required">Lastname is required.</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)