Coldairarrow / EFCore.Sharding

Database Sharding For EFCore
Apache License 2.0
694 stars 144 forks source link

联合主键如何设置 #72

Closed yhmodem closed 3 years ago

yhmodem commented 3 years ago

联合主键如何设置。现在报:Entity type 'SYS_MAIN_TREE' has composite primary key defined with data annotations. To set composite primary key, use fluent API.

Coldairarrow commented 3 years ago

https://www.learnentityframeworkcore.com/configuration/fluent-api/haskey-method#composite-keys

yhmodem commented 3 years ago

我看了这个就是EF原始的DbContext方式,通过重写OnModelCreating完成。 但我写了MyDbContext来重写如何使用到EF.Sharding中呢? ConfigureServices方法中吗? services.UseEFCoreSharding(config => { string conName = Configuration["ConnectionName"]; if (Configuration["LogicDelete"].ToBool()) config.UseLogicDelete(); config.UseDatabase(Configuration.GetConnectionString(conName), Configuration["DatabaseType"].ToEnum()); config.SetEntityAssembly(GlobalData.FXASSEMBLY);
}); services.AddDbContext《MyDbContext》();

这样好像不行。

Coldairarrow commented 3 years ago

https://github.com/Coldairarrow/EFCore.Sharding/blob/master/src/EFCore.Sharding.Tests/EntityTypeConfigurations/Base_UnitTestConfiguration.cs 能不能先了解下相关基础知识