Skip to content
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

Enhancement: TypeMapper for MSSQL (Udt and Spatial) #1023

Closed
Garios opened this issue Jan 21, 2022 · 7 comments
Closed

Enhancement: TypeMapper for MSSQL (Udt and Spatial) #1023

Garios opened this issue Jan 21, 2022 · 7 comments
Assignees
Labels
enhancement New feature or request fixed The bug, issue, incident has been fixed. request A request from the community.

Comments

@Garios
Copy link

Garios commented Jan 21, 2022

For User definied Types (Udt) a general TypeMapper for MSSQL would be nice to have.

Example

For Spatial-Types (e.g. SqlGeography) I use dotMorten's Microsoft.SqlServer.Types. With no additional configuration, you can query spatial-data. Doing Updates or Inserts, you have to define somethings for each property:

FluentMapper.Entity<Address>().PropertyValueAttributes(e => e.Geography, new PropertyValueAttribute[]{ 
        new SqlDbTypeAttribute(System.Data.SqlDbType.Udt),
        new UdtTypeNameAttribute("Geography")
        });
@Garios Garios added the enhancement New feature or request label Jan 21, 2022
@mikependon mikependon added the request A request from the community. label Jan 21, 2022
@mikependon
Copy link
Owner

FYI: We will soon release the last 2 months update but this may not be a part of it. This will be a part of the next release after that release.

@mikependon
Copy link
Owner

mikependon commented Aug 16, 2022

This is a note, the target fix to this is for the user to be able add the following code.

FluentMapper
    .Type<Microsoft.SqlServer.Types.SqlGeography>()
    .PropertyValueAttributes(new[]
    {
        new SqlDbTypeAttribute(SqlDbType.Udt),
        new UdtTypeNameAttribute("Geography")
    });

EDIT:

Also, via the actual PropertyValueAttributeMapper.

PropertyValueAttributeMapper
    .Add<Microsoft.SqlServer.Types.SqlGeography>(e =>
        new[]
        {
            new SqlDbTypeAttribute(SqlDbType.Udt),
            new UdtTypeNameAttribute("Geography")
        });

@mikependon mikependon pinned this issue Aug 16, 2022
@mikependon
Copy link
Owner

mikependon commented Aug 18, 2022

Referencing #1059

@mikependon mikependon added the fixed The bug, issue, incident has been fixed. label Sep 7, 2022
@mikependon mikependon unpinned this issue Sep 7, 2022
@mikependon
Copy link
Owner

The fixes to this will be available on the next version > RepoDB v1.12.10.

@Garios
Copy link
Author

Garios commented Oct 14, 2022

I tried it, but it doesn't work.

Current call will fail:

FluentMapper
	.Type<Microsoft.SqlServer.Types.SqlGeography>()
	.PropertyValueAttributes<Microsoft.SqlServer.Types.SqlGeography>(new PropertyValueAttribute[]
	{
		new SqlDbTypeAttribute(SqlDbType.Udt),
		new UdtTypeNameAttribute("Geography")
	});

//note, that you need to add the type Microsoft.SqlServer.Types.SqlGeography two times.

The problem can be found in TypeMapFluentDefinition.cs

//this is the current line. It calls itself (infinite loop, stack overflow):
public TypeMapFluentDefinition<TType> PropertyValueAttributes<T>(IEnumerable<PropertyValueAttribute> attributes) =>
            PropertyValueAttributes<T>(attributes);

//possible solution, add force-parameter and set it to false
public TypeMapFluentDefinition<TType> PropertyValueAttributes<T>(IEnumerable<PropertyValueAttribute> attributes) =>
            PropertyValueAttributes<T>(attributes, false);

//also I think the generic type T isn't necessary
public TypeMapFluentDefinition<TType> PropertyValueAttributes(IEnumerable<PropertyValueAttribute> attributes) =>
            PropertyValueAttributes(attributes, false);

public TypeMapFluentDefinition<TType> PropertyValueAttributes(IEnumerable<PropertyValueAttribute> attributes, bool force) =>
            PropertyValueAttributes(typeof(TType), attributes, force);


//with these changes, you can write
FluentMapper
	.Type<Microsoft.SqlServer.Types.SqlGeography>()
	.PropertyValueAttributes(new PropertyValueAttribute[]
	{
		new SqlDbTypeAttribute(SqlDbType.Udt),
		new UdtTypeNameAttribute("Geography")
	});

@mikependon
Copy link
Owner

Glad that it is still alpha and not yet beta so this kind of exception can be captured :)
You can as well use the PropertyAttributeMapper class explicitly as an alternative from this buggy code.

@Garios
Copy link
Author

Garios commented Oct 14, 2022

Hello Mike,
I know, this was my last usage. But you can use it, if you add the second parameter force=false. This bypasses the loop-method.

FluentMapper
            .Type<Microsoft.SqlServer.Types.SqlGeography>()
            .PropertyValueAttributes<Microsoft.SqlServer.Types.SqlGeography>(new PropertyValueAttribute[]
            {
                new SqlDbTypeAttribute(SqlDbType.Udt),
                new UdtTypeNameAttribute("Geography")
            }, false);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed The bug, issue, incident has been fixed. request A request from the community.
Projects
None yet
Development

No branches or pull requests

2 participants