在ASP.NET 5项目中使用EF7我尝试在VS Package Manager控制台上添加一个在以下内容中键入以下内容的迁移:
dnx ef migrations add InitialDatabaseSetup
Run Code Online (Sandbox Code Playgroud)
我收到了错误:
Unable to resolve project from C:\Projects\ASPNET5DEMO
Run Code Online (Sandbox Code Playgroud)
该项目位于C:\ Projects\ASPNET5DEMO\src\aspnet5demo.web中
如果使用Developer Command Prompt导航到该路径然后运行命令,那么一切正常......
有没有办法使用Package Manager Console?
我使用ASP.NET Core与ASP.NET身份,并具有以下内容:
User user = await _userManager.FindByEmailAsync(myEmail);
SignInResult result = await _signInManager.PasswordSignInAsync(user, myPassword, true, false);
Run Code Online (Sandbox Code Playgroud)
我得到一个用户,但当我尝试登录用户时,我得到错误:
[Error] An unhandled exception has occurred while executing the request
Run Code Online (Sandbox Code Playgroud)
System.InvalidOperationException:没有配置身份验证处理程序来处理该方案:Microsoft.AspNet.Identity.Application
在Web项目启动文件我有:
public void Configure(IApplicationBuilder applicationBuilder, IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory) {
// Other configuration code lines
applicationBuilder.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
applicationBuilder.UseIdentity();
} // Configure
public void ConfigureServices(IServiceCollection services) {
// Other configuration code lines
services
.AddIdentity<User, Role>()
.AddEntityFrameworkStores<Context, Int32>()
.AddDefaultTokenProviders();
}
Run Code Online (Sandbox Code Playgroud)
我不知道出了什么问题.我试图改变配置,我总是得到同样的错误......
任何的想法?
我正在使用Asp.Net Core和ASP.NET Identity,当我得到一个Claim类型时,我会得到类似的东西
"type":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier",
"value":"123"
Run Code Online (Sandbox Code Playgroud)
如何只获取简单类型名称,例如:
"type":"nameidentifier",
"value":"123"
Run Code Online (Sandbox Code Playgroud)
我知道这是可能的我只是找不到解决方案.
我创建了一个名为MyHelpers的ASP.NET Core RC2类库,并在project.json上获得了以下内容:
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027",
},
"frameworks": {
"netstandard1.5": {
"imports": [
"dnxcore50",
"portable-net452+win81"
]
}
}
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个用于测试的ASP.NET Core RC2类库,命名为MyHelpersTests,并在project.json中获得以下内容:
"testRunner": "xunit",
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027",
"xunit": "2.2.0-beta1-build3239",
"dotnet-test-xunit": "1.0.0-rc2-build10015",
"MyHelpers": "1.0.0"
},
"frameworks": {
"netstandard1.5": {
"imports": [
"dnxcore50",
"portable-net452+win81"
]
}
}
Run Code Online (Sandbox Code Playgroud)
当我编译它时,我得到错误:
Package dotnet-test-xunit 1.0.0-rc2-build10015 is not compatible with netstandard1.5 (.NETStandard,Version=v1.5). Package dotnet-test-xunit 1.0.0-rc2-build10015 supports:
Run Code Online (Sandbox Code Playgroud)
- net451(.NETFramework,Version = v4.5.1) - netcoreapp1.0(.NETCoreApp,Version = v1.0)一个或多个软件包与.NETStandard,Version = v1.5不兼容.
我错过了什么?
我有以下内容:
var a = new List<OrderRule> {
new OrderRule("name", OrderDirection.Ascending),
new OrderRule("age", OrderDirection.Descending)
};
var b = new List<OrderRule> {
new OrderRule("name", OrderDirection.Ascending),
new OrderRule("age", OrderDirection.Descending)
};
var r = a.Equals(b);
Run Code Online (Sandbox Code Playgroud)
即使两个列表包含彼此相等的项,r变量也是假的.OrdeRule类实现IEquality.请注意,当Direction和Property都相等时,两个OrderRules是相等的.
public enum OrderDirection { ASC, DESC }
public class OrderRule : IEquatable<OrderRule> {
public OrderDirection Direction { get; }
public String Property { get; }
public OrderRule(String property, OrderDirection direction) {
Direction = direction;
Property = property;
}
public Boolean Equals(OrderRule other) {
if (other == null)
return …
Run Code Online (Sandbox Code Playgroud) 在ASP.NET Core 1.0.1项目上,使用Entity Framework Core和ASP.NET Identity,我有以下上下文:
public class Context : IdentityDbContext<User, Role, Int32, UserClaim, UserRole, UserLogin, RoleClaim, UserToken> {
public Context(DbContextOptions options) : base(options) { }
protected override void OnModelCreating(ModelBuilder builder) {
base.OnModelCreating(builder);
}
}
Run Code Online (Sandbox Code Playgroud)
以下实体:
public class User : IdentityUser<Int32, UserClaim, UserRole, UserLogin> { }
public class Role : IdentityRole<Int32, UserRole, RoleClaim> { }
public class RoleClaim : IdentityRoleClaim<Int32> { }
public class UserClaim : IdentityUserClaim<Int32> { }
public class UserLogin : IdentityUserLogin<Int32> { }
public class UserRole : …
Run Code Online (Sandbox Code Playgroud) 我有以下两个Entity Framework的Include方法:
public static IIncludableQueryable<TEntity, TProperty> Include<TEntity, TProperty>(
[NotNullAttribute] this IQueryable<TEntity> source,
[NotNullAttribute] Expression<Func<TEntity, TProperty>> navigationPropertyPath)
where TEntity : class;
public static IQueryable<TEntity> Include<TEntity>(
[NotNullAttribute] this IQueryable<TEntity> source,
[NotNullAttribute][NotParameterized] string navigationPropertyPath)
where TEntity : class;
Run Code Online (Sandbox Code Playgroud)
我需要为这两种方法获取MethodInfo.对于我使用的第一个:
MethodInfo include1 = typeof(EntityFrameworkQueryableExtensions)
.GetMethods().First(x => x.Name == "Include" && x.GetParameters()
.Select(y => y.ParameterType.GetGenericTypeDefinition())
.SequenceEqual(new[] { typeof(IQueryable<>), typeof(Expression<>) }));
Run Code Online (Sandbox Code Playgroud)
这有效但当我尝试使用以下内容获取第二个时:
MethodInfo include2 = typeof(EntityFrameworkQueryableExtensions)
.GetMethods().First(x => x.Name == "Include" && x.GetParameters()
.Select(y => y.ParameterType.GetGenericTypeDefinition())
.SequenceEqual(new[] { typeof(IQueryable<>), typeof(String) }));
Run Code Online (Sandbox Code Playgroud)
我收到错误:
此操作仅对泛型类型有效
我错过了什么?
我正在使用Cake构建来构建和部署项目,但在我的脚本中,我有一些服务密码,我不想公开.
是否可以从外部文件(也许是JSON?)读取密码,我不会将其推送到Github?所以这个文件只能在我的电脑里.
Cake有没有标准的方法来做到这一点?
我需要创建一个对象列表 OrganizationEnrolment,它是使用 3 个实体框架实体(User、EnrolmentType 和 OrganizationEnrolment)创建的:
List<OrganizationEnrolment> organizationEnrolments =
context.Organizations
.SelectMany(x => context.Users)
.SelectMany(x => context.EnrolmentTypes)
.Select(y => new OrganizationEnrolment {
EnrolmentType = enrolmentType
Organization = organization,
User = user
})
Run Code Online (Sandbox Code Playgroud)
我的问题是在拥有 SelectMany 后如何从 3 个连接表中获取 enrolmentType、组织和用户?请注意以下代码:
EnrolmentType = enrolmentType,
Organization = organization,
User = user
Run Code Online (Sandbox Code Playgroud)
不起作用,因为我没有变量 enrolmentType、组织和用户。
c# linq linq-to-entities entity-framework entity-framework-core
我需要取两个日期之差的平均值,四舍五入到小数点后两位。
使用实体框架核心,我使用了以下内容:
var average = await games
.Where(x => x.Finish.HasValue)
.AverageAsync(x => Math.Round((x.Finish.Value - x.Start).TotalDays, 2));
Run Code Online (Sandbox Code Playgroud)
这似乎正在内存中运行。
如何计算数据库(SQL)的平均值?