我昨天刚刚了解 Fluent Validation,我认为它非常酷。我已经尝试过并且有效。但我的应用程序目前有多个模型,我必须承认为每个模型编写验证器很有压力。是否有可能用泛型编写它并找到一种方法来验证每个模型?
这就是我的验证器目前的编写方式。但我不知道如何用泛型编写它。
EmployeeValidator.cs
public class EmployeeValidator : AbstractValidator<EmployeeViewModel>
{
private readonly ValidationEntitySettingServices _validationEntitySettingService;
public EmployeeValidator(ValidationEntitySettingServices validationEntitySettingService)
{
_validationEntitySettingService = validationEntitySettingService;
RuleFor(x => x.LastName).NotEmpty().When(x => IsPropertyRequired(x.LastName)).WithMessage("Last Name is a required field!");
RuleFor(x => x.FirstName).NotEmpty().When(x => IsPropertyRequired(x.FirstName)).WithMessage("First Name is a required field!");
RuleFor(x => x.MiddleName).NotEmpty().When(x => IsPropertyRequired(x.MiddleName)).WithMessage("Middle Name is a required field!");
}
public bool IsPropertyRequired(string propertyName)
{
var empValidationSetting = _validationEntitySettingService.GetIncluding("Employee");
if (empValidationSetting != null)
{
return empValidationSetting.ValidationEntityProperties.Any(p => p.PropertyName.Equals(propertyName) && p.IsRequired);
}
else
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢。
不久前我就被介绍给了lodash,而我正在接受一个简单的挑战.我正在使用_.forEach()循环在typescript中对Array的对象执行一个函数.但我需要知道它何时到达最后一次迭代才能执行特定的功能.
_.forEach(this.collectionArray, function(value: CreateCollectionMapDto) {
// do some stuff
// check if loop is on its last iteration, do something.
});
Run Code Online (Sandbox Code Playgroud)
我检查了这个或任何与之相关的文档,index但找不到任何东西.请帮我.
使用 EF-Core for PostgresSQL,我有一个具有 type 字段的实体byte,但决定将其更改为 type byte[]。但是当我进行迁移时,在应用生成的迁移文件时,它引发了以下异常:
Npgsql.PostgresException (0x80004005): 42804: 列“Logo”无法自动转换为类型 bytea
我在互联网上搜索了解决方案,但我看到的只是其他数据类型的类似问题,而不是字节数组。请帮忙。
我想查询一个表和一个字段分组BillPeriodId,我正在按照本文中的示例的方式实现它.以下是进行分组的方法
public List<BillPeriodLine> GetLinesGroupedByPeriod()
{
var linesGrouped = _lineRepository.AllIncluding(p => p.BillPeriod)
.GroupBy(pl => pl.BillPeriodId)
.Select(g => new Group<int, BillPeriodLine>
{
Key = g.Key,
Values = g
});
return new List<BillPeriodLine>(linesGrouped);
}
Run Code Online (Sandbox Code Playgroud)
可发现类型
public class Group<T, K>
{
public K Key;
public IEnumerable<T> Values;
}
Run Code Online (Sandbox Code Playgroud)
但它强调g.Key了以下错误消息:
无法将类型'int'隐式转换为'BillTracker.Entities.BillPeriodLine'
除了我正在使用lamda表达式之外,它正是在示例中完成的方式.它使用LINQ语句提供相同的错误.我不知道我做错了什么.Sompne指向正确的方向吗?
static_configs我的 prometheus.yml 配置文件中的目标之一使用基本身份验证进行保护。因此,在 Prometheus 目标页面中始终针对该目标显示描述为“拒绝连接”的错误。
我研究了如何设置 prometheus 以在尝试抓取该特定目标时提供安全凭据,但找不到任何解决方案。我发现的是如何scrape_config在文档中的部分进行设置。这对我不起作用,因为我还有其他不受basic_auth. 请帮我解决这个挑战。
.yml关于我的挑战,这是我的配置的一部分。
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
scrape_timeout: 5s
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:5000']
labels:
service: 'Auth'
- targets: ['localhost:5090']
labels:
service: 'Approval'
- targets: …Run Code Online (Sandbox Code Playgroud) c# ×2
ef-core-2.1 ×1
generics ×1
linq ×1
lodash ×1
monitoring ×1
npgsql ×1
prometheus ×1
typescript ×1