3

We have a table in our project with a primary key of HIERARCHYID type:

CREATE TABLE [dbo].[OurTable]
(
    [Id]                HIERARCHYID     NOT NULL,
    <other fields>
)

and the corresponding class to use with Dapper queries:

[Table("OurTable")]
public class OurTable
{
    [ExplicitKey]
    public SqlHierarchyId Id { get; private set; }
    <other fields>
}

The object is created and initialised, the InsertAsync is called, and promptly fails with "Cannot insert Null into Id field", even though debugging shows that Id isn't null and has the correct value at the point where we try to insert.

The [ExplicitKey] attribute was added specifically to fix cases like this, but it looks like it... doesn't? What else can I be missing here?

Darth Veyda
  • 828
  • 2
  • 12
  • 23

1 Answers1

2

If you never solved this issue, it may actually be an existing bug in Dapper seen here on GitHub.

user2078938
  • 947
  • 1
  • 9
  • 22
  • Yeah, looks like that's it - thank you, I've never found this one when I was digging through their issue tracker. (Looks like the [fix](https://github.com/StackExchange/Dapper/pull/704) has been stuck in PR limbo since June. Sigh) – Darth Veyda Nov 15 '18 at 01:56