Dapper: TVP in .NET Core 2.0

Created on 9 Aug 2017  路  18Comments  路  Source: StackExchange/Dapper

DataTable is back in .NET Core 2.0. Yay!

Converting some of my code I have run into an issue. SetTypeName is not available in .NET Core, so obviously when trying to use DataTable for a TVP without it you get a NotSupportedException:

System.NotSupportedException: The member Ids of type System.Data.DataTable cannot be used as a parameter value
at Dapper.SqlMapper.LookupDbType(Type type, String name, Boolean demand, ITypeHandler& handler)
at Dapper.SqlMapper.CreateParamInfoGenerator(Identity identity, Boolean checkForDuplicates, Boolean removeUnused, IList`1 literals)
at Dapper.SqlMapper.GetCacheInfo(Identity identity, Object exampleParameters, Boolean addToCache)
at Dapper.SqlMapper.d__29.MoveNext()

So how do I set the type for a TVP in .NET Core 2.0 with Dapper?

I found this issue that seems to be discussing things regarding TVP back in May. One of the replies has a code example using table.ExtendedProperties["dapper:TypeName"]. I gave that a try and am getting the same error.

Maybe this isn't available yet? I'm using v1.50.2 on .NET Core 2.0 preview 2.

Most helpful comment

I've pushed alpha packages to NuGet with netstandard2 support, for example: https://www.nuget.org/packages/Dapper/1.50.4-alpha1-00070

If anyone has time to test and give us feedback it'd be much appreciated. Thanks!

All 18 comments

I just realized that the referenced issue points to the netstandard2 branch here. So it looks like Dapper just isn't released for that yet (I think?).

Still, it would be good to get some official confirmation on how to use TVP since it seems ExtendedProperties["dapper:TypeName"] isn't documented anywhere yet.

Since .NET Core 2.0 is now live, can we expect an update for this soon?

@kspearrin I've just opened a PR on this here: https://github.com/StackExchange/Dapper/pull/836 - sorry lots of upgrades happening for 2.0 and Dapper is one of many on my plate atm.

@NickCraver awesome. Any idea on the timeline for prod release?

@kspearrin I'm hoping to get to it this week (at least an alpha on NuGet), worst case is next. I was on vacation last week so I dunno what awaits me.

@NickCraver Thanks. Just trying to plan properly since this is currently a blocker for us.

@NickCraver Just FYI. I decided to temporarily reference Dapper master branch locally so we could get past the blocker. Everything is working great on .NET Core 2.0 now. https://github.com/bitwarden/core/commit/7a134148535a72bb7542aa2f5437a6a6c6d011fc

@NickCraver Any update on this? We're still successfully referencing local dlls for now, but it would be great to switch back to nuget so our CI builds start working again :)

@NickCraver Thanks so much for your work on Dapper - would love an update on this as I'm trying to push my new company to use Dapper and want to wait until this resolved before I nudge them gently to use it in our latest prototype...

I would also like to see a version that is working with .net 2.0 as we are upgrading the solutions in our project. Hope to hear about is really soon. Thank you.

For those wanting to get around this and continue developing, I came up with a temporary solution. Instead of resolving the dependency on Dapper via Nuget, I cloned the Dapper repository, and included it as a project reference in Visual Studio. From here, adding a Nuget dependency on System.Data.SqlClient (v 4.4.0) meant everything built perfectly.

Eventually, I will return the Dapper dependency to being based on Nuget, but for now it just builds along with the rest of my solution.

Any update on getting a nupkg with netstandard2.0 support even if its a -pre release?

I've pushed alpha packages to NuGet with netstandard2 support, for example: https://www.nuget.org/packages/Dapper/1.50.4-alpha1-00070

If anyone has time to test and give us feedback it'd be much appreciated. Thanks!

@NickCraver Working great here. Thanks.

Hi @kspearrin
Can you give me a code example?
I am trying to use it with .net standard 2.0(and Dapper/1.50.4-alpha1-00070) and it says

The member Foo of type System.Data.DataTable cannot be used as a parameter value

The same exact code used to work on full .net framework. Am I suppose to change anything?
Thank you!

Thank you @kspearrin. The real problem were some out of date packages. Nevertheless thank you again.

Dapper 1.50.4 stable is now released with all these bits: https://www.nuget.org/packages/Dapper/1.50.4

Enjoy! And please let me know if you run into any issues.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

huobazi picture huobazi  路  4Comments

PeterWone picture PeterWone  路  5Comments

valinoment picture valinoment  路  4Comments

silkfire picture silkfire  路  4Comments

CrescentFresh picture CrescentFresh  路  4Comments