0%

20180710工作日誌(EntityFramework; MongoDB; Typhoon)

接昨日 (在 EF Core 上使用 MongoDB)

EntityFrameworkCore.MongoDb

範例CODE跑起來OK

套到自己的CODE上出現錯誤

1
2
3
4
5
6
7
8
System.InvalidOperationException: 
'A key cannot be configured on 'PocketHiAccount'
because it is a derived type.
The key must be configured on the root type 'IdentityUser<Guid>'.
If you did not intend for 'IdentityUser<Guid>' to be included in the model,
ensure that it is not included in a DbSet property on your context,
referenced in a configuration call to ModelBuilder,
or referenced from a navigation property on a type that is included in the model.'

金拍垮

問題原因猜測:
EFCode-MongoDB Provider & IdentityDbContext 在PrimaryKey部分會衝突

在範例Code內是使用 MongoDB 的 ObjectId
與IdentityUser<Tkey> 衝突到
且範例Code是使用DbContext
可能跟這個有關係

所以試著在範例CODE的 DbContext 改成 IdentityDbContext

1
public class ZooDbContext : IdentityDbContext<IdentiryUser, IdentityRole, ObjectId>

還是錯 ㄏㄏ

1
2
System.InvalidOperationException: 
A key cannot be configured on 'PocketHiAccount' because it is a derived type. The key must be configured on the root type 'IdentityUser<ObjectId>'. If you did not intend for 'IdentityUser<ObjectId>' to be included in the model, ensure that it is not included in a DbSet property on your context, referenced in a configuration call to ModelBuilder, or referenced from a navigation property on a type that is included in the model.

Q_Q

颱風來啦 四點下班

大家8888888888888888888888888888