-
Notifications
You must be signed in to change notification settings - Fork 242
Fix mapping issues around arrays and byte arrays #1196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Caching is already done by TypeMappingSource in EF
internal static bool IsArrayOrGenericList(this Type type) | ||
=> type.IsArray || type.IsGenericList(); | ||
|
||
internal static bool TryGetElementType(this Type type, out Type? elementType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to return an element type as is or null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure... This means that instead of:
if (!operand.Type.TryGetElementType(out var operandElementType))
we need to write:
if (!(operand.Type.GetElementType() is Type operandElementType))
which seems considerably more verbose/ugly. Another small advantage of TryGetElementType is that you can put an existing variable.
Both patterns seem to have advantages and disadvantages...
{ | ||
// PostgreSQL array type names are the element plus [] | ||
var clrType = mappingInfo.ClrType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When could clrType
be equal to null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When reverse engineering an existing database - all you have is the store type from PostgreSQL, and you're creating the C# code model.
src/EFCore.PG/Storage/Internal/Mapping/NpgsqlArrayTypeMapping.cs
Outdated
Show resolved
Hide resolved
src/EFCore.PG/Storage/Internal/Mapping/NpgsqlArrayTypeMapping.cs
Outdated
Show resolved
Hide resolved
if (clrType == null || !ClrTypeMappings.TryGetValue(clrType, out var mapping)) | ||
if (clrType == null || | ||
!ClrTypeMappings.TryGetValue(clrType, out var mapping) || | ||
storeTypeName != null && mapping.StoreType != storeTypeName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should ClrTypeMappings
be checked last?
storeTypeName != null && mapping.StoreType != storeTypeName) | |
storeTypeName != null && storeTypeName != mapping.StoreType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should ClrTypeMappings be checked last?
Can you explain what you mean? Assuming there's a mapping that corresponds to the given clrType, we want to verify that the storeTypeName corresponds to it too (but only if it's given).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that you can change the order of execution and do lookup as the last step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the lookup provides mapping
, which is used afterwards? Or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but you know I am a bit maniacal (:
Co-Authored-By: Yoh Deadfall <yoh.deadfall@hotmail.com>
? elementNpgsqlTypeMapping.NpgsqlDbType | ||
: elementMapping.DbType.HasValue | ||
? new NpgsqlParameter { DbType = elementMapping.DbType.Value }.NpgsqlDbType | ||
: default(NpgsqlDbType?)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To large indentation, but it's a nit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how Rider likes it... I've stopped fighting :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I know, it's adjustable. For me it doesn't recommend such things, am using a cleaned up editor config from dotnet/runtime
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. If you really feel like it you can work on our .editorconfig :)
Fixes #1189