版本号
问题
我正在docker中运行ASP.NET Core项目。当我docker-compose起来时,我得到以下信息:
Unhandled Exception: Microsoft.Build.BackEnd.NodeFailedToLaunchException: The FileName property should not be a directory unless UseShellExecute is set. ---> System.ComponentModel.Win32Exception: The FileName property should not be a directory unless UseShellExecute is set.
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at Microsoft.Build.BackEnd.NodeProviderOutOfProcBase.LaunchNode(String msbuildLocation, String commandLineArgs)
--- End of inner exception stack trace ---
at Microsoft.Build.CommandLine.MSBuildApp.BuildProject(String projectFile, String[] targets, String toolsVersion, Dictionary`2 globalProperties, Dictionary`2 restoreProperties, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, Int32 cpuCount, Boolean enableNodeReuse, TextWriter …Run Code Online (Sandbox Code Playgroud) 假设我在 EF Core 中有一个查询,如下所示:
MethodWithDomainLogic() {
return this.dbContext.People.Where(...).ToListAsync();
}
Run Code Online (Sandbox Code Playgroud)
现在,为了将我的域层与我的数据访问层分离,我希望这个方法在我的域程序集中,并且该程序集没有对 EFCore 的引用。所以它看起来像:
在领域层:
public interface IEntities {
IQueryable<Person> People { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在数据层:
private IEntities entities; // injected with a dbcontext that implements the IEntities interface.
public Task<IEnumerable<Person>> MethodWithDomainLogic() {
return this.entities.People.Where(...).ToListAsync(); // How to do this without referencing EFCore?
}
Run Code Online (Sandbox Code Playgroud)
根据我的理解,这是不可能的,因为 Linq 本身不支持异步查询。
我已经通过在域层中使用 EFCore 接口设置我自己的接口解决了这个问题(基本上是复制并粘贴了 ToListAsync 和 FirstAsync 等方法......)然后在我的数据层中实现它,只需调用EFCore 版本。然而,这是非常混乱和复杂的。
有更好的解决方案吗?我希望我的域方法在没有 EFCore 的情况下使用异步编程和 Linq,但要在数据层中使用 EFCore 实现 Linq/异步编程。
我在我的代码中使用方法帖子看到了这一点,但无法弄清楚它到底做了什么。
<form action="." method="POST" class="form-vertical">
Run Code Online (Sandbox Code Playgroud) 我的团队多年前覆盖了用户的身份验证方法,以针对 LDAP 而不是 djangos 模型后端进行身份验证。
此方法查看用户的 LDAP。如果用户存在正确的用户名和密码,它会获取或创建用户(这意味着用户不必作为模型对象存在于 Django 数据库中供某人登录)。
该方法将新创建的密码保留为无。然后设置所有其他信息。
我注意到,在验证用户后,如果它们有效,则调用用户的 set_unusable_password。在评论中,他们写道它覆盖了 Django 的内置密码处理......这显然是有道理的。但是我不知道为什么他们需要这样做,因为我们已经覆盖了身份验证方法。
我通过删除 set_unusable_password 来测试这一点,以便密码保留为 None 并且验证有效。他们仍然能够使用存储在 LDAP 上的密码登录。您仍然无法将模型中的密码覆盖为与 LDAP 不同的密码并使用该密码登录。
所以基本上 set_unusable_password 调用除了创建一个密码之外没有任何影响......无论如何都没有使用。
我唯一能想到的是,它可能是旧版本 Django 中问题的解决方案(我们现在是 1.11)。
在源代码和文档中花了很多时间之后,我不明白我们为什么需要它。
为什么会在那里?写它的人现在已经离开了,所以我无法解释他们为什么这样做。如果我删除它,会不会有任何不需要的副作用?
我将我的项目从 django 1.6 升级到 1.8。迁移时,我收到 contenttype 错误:
django.db.utils.IntegrityError: null value in column "name" violates not-null constraint
Run Code Online (Sandbox Code Playgroud)
详细信息:失败的行包含(31、null、django_auth、adgroup)。
我尝试迁移 contenttype 0002 但它告诉我:
django.db.utils.ProgrammingError: relation "django_content_type" already exists
Run Code Online (Sandbox Code Playgroud)
我如何克服第一个迁移文件?