File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
src/EFCore.Ydb/src/Metadata/Conventions Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ public override ConventionSet CreateConventionSet()
1313 {
1414 var coreConventions = base . CreateConventionSet ( ) ;
1515 coreConventions . Add ( new YdbStringAttributeConvention ( Dependencies ) ) ;
16+ coreConventions . Add ( new YdbValueGenerationConvention ( Dependencies , RelationalDependencies ) ) ;
1617 return coreConventions ;
1718 }
1819}
Original file line number Diff line number Diff line change 1+ using System . Linq ;
2+ using Microsoft . EntityFrameworkCore ;
3+ using Microsoft . EntityFrameworkCore . Metadata ;
4+ using Microsoft . EntityFrameworkCore . Metadata . Conventions ;
5+ using Microsoft . EntityFrameworkCore . Metadata . Conventions . Infrastructure ;
6+ using Microsoft . EntityFrameworkCore . Metadata . Internal ;
7+
8+ namespace EntityFrameworkCore . Ydb . Metadata . Conventions ;
9+
10+ public class YdbValueGenerationConvention (
11+ ProviderConventionSetBuilderDependencies dependencies ,
12+ RelationalConventionSetBuilderDependencies relationalDependencies )
13+ : RelationalValueGenerationConvention ( dependencies , relationalDependencies )
14+ {
15+ protected override ValueGenerated ? GetValueGenerated ( IConventionProperty property )
16+ {
17+ if ( property . DeclaringType . IsMappedToJson ( )
18+ #pragma warning disable EF1001 // Internal EF Core API usage.
19+ && property . IsOrdinalKeyProperty ( )
20+ #pragma warning restore EF1001 // Internal EF Core API usage.
21+ && ( property . DeclaringType as IReadOnlyEntityType ) ? . FindOwnership ( ) ! . IsUnique == false )
22+ {
23+ return ValueGenerated . OnAdd ;
24+ }
25+
26+ var declaringTable = property . GetMappedStoreObjects ( StoreObjectType . Table ) . FirstOrDefault ( ) ;
27+ if ( declaringTable . Name == null )
28+ {
29+ return null ;
30+ }
31+
32+ return property . GetComputedColumnSql ( declaringTable ) != null
33+ ? ValueGenerated . OnAddOrUpdate
34+ : property . GetDefaultValueSql ( declaringTable ) != null
35+ ? ValueGenerated . OnAdd
36+ : null ;
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments