Skip to content

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

Merged
merged 4 commits into from
Jan 14, 2020
Merged

Conversation

roji
Copy link
Member

@roji roji commented Jan 13, 2020

Fixes #1189

internal static bool IsArrayOrGenericList(this Type type)
=> type.IsArray || type.IsGenericList();

internal static bool TryGetElementType(this Type type, out Type? elementType)
Copy link
Contributor

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.

Copy link
Member Author

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;
Copy link
Contributor

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?

Copy link
Member Author

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.

if (clrType == null || !ClrTypeMappings.TryGetValue(clrType, out var mapping))
if (clrType == null ||
!ClrTypeMappings.TryGetValue(clrType, out var mapping) ||
storeTypeName != null && mapping.StoreType != storeTypeName)
Copy link
Contributor

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?

Suggested change
storeTypeName != null && mapping.StoreType != storeTypeName)
storeTypeName != null && storeTypeName != mapping.StoreType)

Copy link
Member Author

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).

Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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 (:

@roji roji requested a review from YohDeadfall January 14, 2020 18:22
? elementNpgsqlTypeMapping.NpgsqlDbType
: elementMapping.DbType.HasValue
? new NpgsqlParameter { DbType = elementMapping.DbType.Value }.NpgsqlDbType
: default(NpgsqlDbType?));
Copy link
Contributor

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.

Copy link
Member Author

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 :)

Copy link
Contributor

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.

Copy link
Member Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception when doing a Contains query against an enum field based on byte
2 participants