我在 VS 2017(版本 15.5)中创建了一个新的 ASP.NET Core 2 MVC 项目,将用户 ID 类型从字符串更改为 Guid(也将 ApplicationUser 类名更改为 User),添加了我的模型,然后
Add-Migration Init
Update-Database
Run Code Online (Sandbox Code Playgroud)
但它会产生错误并且不会创建数据库。
The object 'PK_AspNetUserTokens' is dependent on column 'UserId'.
ALTER TABLE ALTER COLUMN UserId failed because one or more objects access this column.
Run Code Online (Sandbox Code Playgroud)
这是我的上下文:
public class ApplicationDbContext : IdentityDbContext<User, IdentityRole<Guid>, Guid>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<TvShow> TvShows { get; set; }
public DbSet<Episode> Episodes { get; set; }
public DbSet<Subscription> Subscriptions { get; set; }
public DbSet<Notification> …Run Code Online (Sandbox Code Playgroud) sql-server asp.net entity-framework entity-framework-core asp.net-core-2.0
我可以查询并获取距客户最近的位置(有学位):
serviceQuery = serviceQuery.Where(s => s.Location.Distance(currentLocation) < <degree>)
.OrderBy(s => s.Location.Distance(currentLocation));
Run Code Online (Sandbox Code Playgroud)
位置是NetTopologySuite.Geometries.PointC# 和 SQL Server 中的类型geography。
如何在查询中提供米而不是度数,并获取米距离而不是度数?在客户端将结果度数转换为米是可以接受的。
在 flexbox 中,我有 2 个未包装的连续元素。第一个具有确定的宽度。我希望第二个元素占用可用空间,所以我使用这个:
flex: 1 1 100%;
Run Code Online (Sandbox Code Playgroud)
到目前为止没有问题。但是在第二个元素内部有额外内容的页面中,元素的宽度会增长到它的父元素的宽度(因为我max-width: 100%在它上面使用过),然后它会超出 flex 容器。如果我使用,wrap则元素会转到下一行,但我不想包装它们。
所以这是我的问题:如何将 flexbox 内元素的宽度设置为完全等于可用空间?不多也不少。
public class MyEntity
{
public string Id { get; set; }
//...
}
Run Code Online (Sandbox Code Playgroud)
配置:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//...
modelBuilder.Entity<MyEntity>()
.Property(e => e.Id)
.ValueGeneratedOnAdd();
}
Run Code Online (Sandbox Code Playgroud)
这是先前开发人员的代码,它导致该列的 GUID 值。但是在 C# 中我不得不处理字符串,所以我决定改变模型。
public class MyEntity
{
public Guid Id { get; set; }
//...
}
Run Code Online (Sandbox Code Playgroud)
我ValueGeneratedOnAdd()从 Fluent API 配置中删除了代码。
我得到了column "Id" cannot be cast automatically to type uuid错误。
我认为这个信息的关键是这个automatically词。
现在我的问题是,由于该列上的值已经是 GUID/UUID,有没有办法告诉 Postgres 将varchar类型更改为uuid并将当前字符串值转换为 UUID 并将其放入列中?我猜应该有一个 SQL 脚本可以做到这一点而不会丢失任何数据。
postgresql npgsql entity-framework-core entity-framework-migrations
sql-server ×2
asp.net ×1
asp.net-core ×1
css ×1
entity-framework-migrations ×1
flexbox ×1
html ×1
npgsql ×1
postgresql ×1
spatial ×1