我正在使用ASP.NET 5 rc1和Entity 7 rc1 over coreclr以及示例代码第一次迁移项目.
我正在研究如何管理实体中的并发性,但我找不到有关实体7的推荐并发处理实践的任何好的更新信息.
我有几个实体,他们都实现了接口:
public interface IVersionedModel
{
byte [] RowVersion { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
例如:
public class User : IVersionedModel
{
public Guid UserId { get; set; }
public string Name { get; set; }
public byte[] RowVersion { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
而是将属性添加[Timestamp]到每个RowVersion列,我更喜欢使用fluent配置,因此在我的DbContext中,我为每个实体指定了我希望该列作为行版本处理.
然而,实体7似乎不再支持该选项,.IsRowVersion()
但它具有选项IsConcurrencyToken(),这应该足够,但在代码首次迁移时,它生成可空的varbinary列,并且在插入/更新行时,它不会自动递增.
我想知道最好的办法是在更新或在数据库中插入实体时通过增加版本来显式管理每行的版本.这是我的DbContext
public class AppDbContext : DbContext
{
public AppDbContext() : base()
{
}
public DbSet<User> Users { get; set; } …Run Code Online (Sandbox Code Playgroud) 我有一个项目,其中前端JavaScript指定要排序的列的列表.
然后在后端我有多层应用程序.典型情况
请注意,System.Linq.DynamicDNX Core v5.0或.NET Platform v5.4不支持,因此我无法使用该库.
我在我的Things存储库中有以下实现:
public async Task<IEnumerable<Thing>> GetThingsAsync(IEnumerable<SortModel> sortModels)
{
var query = GetThingsQueryable(sortModels);
var things = await query.ToListAsync();
return things;
}
private IQueryable<Thing> GetThingsQueryable(IEnumerable<SortModel> sortModels)
{
var thingsQuery = _context.Things
.Include(t => t.Other)
.Where(t => t.Deleted == false);
// this is the problematic area as it does not return a valid queryable
string orderBySqlStatement = GetOrderBySqlStatement(sortModels);
thingsQuery = thingsQuery.FromSql(orderBySqlStatement);
return thingsQuery ;
}
/// this …Run Code Online (Sandbox Code Playgroud) linq dynamic-sql sql-order-by entity-framework-core asp.net-core
在智威汤逊RFC似乎并不具有包含复杂阵列,如任何问题:
{
"email": "test@test.com",
"businesses": [
{
"businessId": "1",
"businessName": "One",
"roles": [
"admin",
"accountant"
]
},
{
"businessId": "2",
"businessName": "Two",
"roles": [
"support"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
对于我们的需求而言,这似乎是一个理想的场景,因为作为令牌的一部分,我们希望拥有一个用户可以访问的业务列表,以及他为每个业务所拥有的角色(它是其身份的一部分).API的授权策略稍后将理解这些组并应用所需的授权逻辑.
我已经看到,与IdentityServer4索赔被添加到ProfileDataRequestContext的IEnumerable<Claim> IssuedClaims财产.
这个复杂的索赔结构是否有任何推荐的替代方案?如果没有,有没有办法用IdentityServer4构建该结构(可能是一些扩展?)或唯一的方法是手动序列化JSON,因为Claim似乎只接受一个字符串?
PS:我已经看到了这个问题和另一个问题,其中一个Identity Server的作者谈到了类似的反模式.不确定反模式是否在索赔中具有复杂的索赔结构或"授权实现细节".
对此的任何建议都会很棒!
更新:
在给出一些想法后,我同意有一个复杂的声明层次结构是不可取的,我可以通过为每个businessId添加前缀角色的脏解决方案解决这个问题.像这样的东西:
{
"email": "test@test.com",
"roles": [
"1_admin",
"1_accountant",
"2_support"
],
"businesses": [
"1_One",
"2_Two"
]
}
Run Code Online (Sandbox Code Playgroud)
这样我保持一个简单的结构,稍后,在客户端或API我可以阅读声明,并找出1具有名称的业务的ID One,它具有角色admin和account.
这会是一个更好的解决方案吗?
我有几个使用Asp.Net Core 1.0和Entity Framework Core 1.1.0的项目
我有一个代码第一个迁移方法,我通过Visual Studio 2015发布到Azure.
我以前在Azure Sql Server中应用迁移的方法是在发布上启用一个复选框:"实体框架迁移 - 在发布时应用此迁移",我在其中输入连接字符串.
我更新了几个软件包,现在对于我的一个项目,我没有看到此选项在发布时应用迁移.我可以看到它试图发现数据上下文,但它没有找到任何东西(虽然它在同一个项目中...)
见下文:
我怀疑它与项目的某些依赖版本有关,而不是与我的IDE有关,因为我对两个项目都使用相同的Visual Studio(2015更新3).
我找不到有关此信息.什么依赖允许这个选项?如果我发现哪个版本存在问题,那么剩下的问题是如何在发布时应用迁移?
这两个项目都在Web项目中进行迁移,两个项目都在使用 "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0"
更新1:我设法找到了涉及的内容.似乎如果我使用这些依赖项:
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final"
Run Code Online (Sandbox Code Playgroud)
Visual Studio能够查找数据上下文,并提供在发布时应用迁移的选项.但是,如果我使用这些依赖项的较新版本,例如:
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Design": "1.1.0"
Run Code Online (Sandbox Code Playgroud)
然后,应用迁移的选项消失了,VS在发布时无法找到任何数据上下文.
我需要了解迁移事物和Asp.Net Core的最新状态.
publish ef-migrations entity-framework-core visual-studio-2015 asp.net-core
如何在 AspNet Core 中处理空查询参数?
假设我们有一个查询
?key1=foo1&key1=foo2&key2=&key3=null
在解析它时,我希望在解析这个 URL 时有某种 Dictionary> 结果,例如:
我的问题是:我应该如何处理空查询参数?
注意:我不能简单地定义查询参数并假设不存在的查询参数为空。但我认为如果需要,应该将 null 视为显式查询参数中的有效值。
根据这个线程:How to send NULL in HTTP query string? 标准是传递编码的空值:见https://www.w3schools.com/tags/ref_urlencode.asp
所以如果我想传递一个空值,我应该这样做: ?key1=foo1&key1=foo2&key2=&key3=%00
问题是我不知道如何解码它以便将 %00 解析为空值。
我尝试了以下方法:
public Dictionary<string, List<string>> CreateFromQuery(string query)
{
if (query == null)
{
return new Dictionary<string, List<string>>();
}
var queryDictionary = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(query);
var result = queryDictionary.ToDictionary(kv => kv.Key, kv => kv.Value.ToList());
return result;
} …Run Code Online (Sandbox Code Playgroud) 我将许多应用程序模型和接口拆分为自己的 nuGet 包。
问题是:在创建有关依赖项定义的 nuGet 包时,是否有任何好的实践推荐策略?
有时 apackage A取决于 a package B。如果我没有package B在我的 nuspec 上声明特定版本package A,当我稍后在任何解决方案中导入package AnuGet 包时,它可能会在运行时失败,因为子依赖项不可用。
有时依赖树甚至会更深。但如果我明确地将依赖项添加到每个 nuspec 文件中,那么我稍后可能会发现版本冲突。
问题是:如果一切都在我的控制之下,处理这些事情的推荐策略是什么?我是否应该只在项目的依赖项“不明显”时指定依赖项(例如:导入 nuGet 包装器的项目在运行时需要但不直接使用的第三方库)?我应该总是这样做,然后以不同的方式处理版本冲突吗?任何有关这方面的良好信息来源将不胜感激,因为我找到了几个例子,但没有推荐某种特定的做事方式。
附件:我创建 nuGet 包的方式是包含我手动编辑的 nuspec 文件。例如,如果我有以下解决方案结构:
ToolBelt.CityContracts.sln
-ToolBelt.CityContracts.NuGet
--ToolBelt.CityContracts.NuGet.nuspec
-ToolBelt.CityContractsOne
-ToolBelt.CityContractsTwo
Run Code Online (Sandbox Code Playgroud)
ToolBelt.CityContractsOne我有ToolBelt.CityContractsTwo我的 C# 源文件。在ToolBelt.CityContracts.NuGet项目中,我添加了一个引用ToolBelt.CityContractsOne并ToolBelt.CityContractsTwo确保 nuspec“知道”源文件在哪里。
然后 nuspec 看起来像这样:
ToolBelt.CityContracts.sln
-ToolBelt.CityContracts.NuGet
--ToolBelt.CityContracts.NuGet.nuspec
-ToolBelt.CityContractsOne
-ToolBelt.CityContractsTwo
Run Code Online (Sandbox Code Playgroud)
直到这里一切都很标准。
nupkgs然后我使用 nuget 命令工具在使用以下命令调用的文件夹内生成 nuget 包:
nuget pack ToolBelt.CityContracts.NuGet.nuspec -Version $VERSION -OutputDirectory nupkgs -Prop …Run Code Online (Sandbox Code Playgroud) 我看过类似的帖子
pip install vs python3 -m pip install
这并没有真正澄清这个问题。我是 Python 的新手,只是按照基本的 python 3 教程,在那里他们提到 pip 作为依赖管理器,他们提到它应该用作pip install dependency_here
我正在使用 Python 3.8.0,在 Windows 上全新安装(对于所有用户,因此它安装在 下C:\Program Files (x86)\Python38-32)
我无法运行 pip 命令。我收到一个模块错误,我不知道是怎么回事。
$ pip --version
Traceback (most recent call last):
File "c:\program files (x86)\python38-32\lib\runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\program files (x86)\python38-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Program Files (x86)\Python38-32\Scripts\pip.exe\__main__.py", line 9, in <module>
TypeError: 'module' object is not callable
Run Code Online (Sandbox Code Playgroud)
但是,我可以使用python -m pip …
我在处理某些 Gitlab CI 作业时遇到问题,在这些作业中我指定了仅在文件存在时才运行的规则。
这是我的.gitlab-ci.yml:
stages:
- build
- test
#Jobs
build:
stage: build
script:
- dotnet restore --no-cache --force
- dotnet build --configuration Release --no-restore
artifacts:
paths:
- test/
expire_in: 1 week
unit_tests:
stage: test
script: dotnet vstest test/*UnitTests/bin/Release/**/*UnitTests.dll --Blame
rules:
- exists:
- test/*UnitTests/bin/Release/**/*UnitTests.dll
integration_tests:
stage: test
script: dotnet vstest test/*IntegrationTests/bin/Release/**/*IntegrationTests.dll --Blame
rules:
- exists:
- test/*IntegrationTests/bin/Release/**/*IntegrationTests.dll
Run Code Online (Sandbox Code Playgroud)
unit_tests我只想当文件夹*UnitTests.dll中的 bin 下有test/且integration_tests仅当文件夹*IntegrationTests.dll中的 bin 下也有时运行test/。
问题是这两项工作都被完全忽略了。换句话说,Gitlab …
我刚刚注册了 SendGrid,它看起来是一个不错的产品。它适用于我尝试过的场景,但现在我需要添加一些自动化集成测试。
我看到 SendGrid 有一个名为 Sandbox 的东西可以启用,如果电子邮件验证正确,它将在发送电子邮件时返回 OK 状态,但电子邮件不会到达任何收件箱,也不会产生费用(不消耗积分)。从理论上讲,这听起来很适合我想要的。
我已经使用完全访问 API 密钥成功尝试了它,但我不想在我的源代码中添加真正的 API 密钥。我想添加最受限制的可能(仅用于电子邮件测试)。
我已经看到我可以配置 API 密钥的范围,并且有一个名为“测试电子邮件”的选项,但是当我使用该受限密钥在沙箱模式下发送电子邮件时,我收到未经授权的错误。
问题是:我可以在 SendGrid 中使用沙箱模式配置一个非常受限的 Api Key 来进行简单的电子邮件测试吗?

我正在使用 .NET 客户端,这是我的代码,但我想这应该是无关紧要的。
public async Task SendEmail(
string fromEmail,
string fromName,
string toEmail,
string subject,
string plainTextContent,
string htmlContent)
{
var apiKey = "ThisIsTheApiKeyWithRestrictedPermissionsGeneratedAtMySendGridDashboard"
var client = new SendGridClient(apiKey);
var sandboxMode =
new SandboxMode
{
Enable = true
};
var mailSettings =
new MailSettings
{
SandboxMode = sandboxMode
};
var from = new EmailAddress(fromEmail, fromName);
var …Run Code Online (Sandbox Code Playgroud) 有一个类似的问题,但它不使用AWS::ApiGatewayV2::Stage,我需要AutoDeploy似乎只有 V2 提供的。
如何在 AWS API Gateway 中使用 CloudFormation 启用 CloudWatch 日志并记录完整消息数据(如图所示)?
我在阶段文档中找不到任何内容 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-deploymentid
我正在使用自动部署的阶段。我能够创建日志组、在 CloudWatch 中写入日志的 IAM 角色,但我无法启用日志记录本身。
wsApiGateway:
Type: AWS::ApiGatewayV2::Api
Properties:
Name: foo-ws-gateway
Description: Api Gateway for Websockets
ProtocolType: WEBSOCKET
RouteSelectionExpression: $request.body.action
DisableExecuteApiEndpoint: true # I use custom domain
# routes and integrations ommitted.
wsApiStage:
Type: AWS::ApiGatewayV2::Stage
DependsOn:
- wsConnectRoute
- wsSendRoute
- wsDisconnectRoute
Properties:
StageName: production
Description: Autodeploy in production
AutoDeploy: true
ApiId: !Ref wsApiGateway
AccessLogSettings:
DestinationArn: !GetAtt wsApiGatewayLogGroup.Arn
Format: '{"requestTime":"$context.requestTime","requestId":"$context.requestId","httpMethod":"$context.httpMethod","path":"$context.path","routeKey":"$context.routeKey","status":$context.status,"responseLatency":$context.responseLatency, …Run Code Online (Sandbox Code Playgroud) asp.net-core ×4
c# ×2
claims ×1
dynamic-sql ×1
gitlab ×1
gitlab-ci ×1
http ×1
jwt ×1
linq ×1
nuget ×1
nuspec ×1
pip ×1
publish ×1
python-3.x ×1
sendgrid ×1
sql-order-by ×1
url ×1