简体   繁体   中英

NotSupportedException when inserting with Dapper

I'm trying to insert a bunch of fogbugz cases into my own database but get a NotSupportedException: The member OutlineUri of type System.Uri cannot be used as a parameter value.

By creating args before passing it in I was able to ensure that I'm not referencing a null object (from this SO question). I can see that fogbugzCase.OutlineUri has a valid value when the exception is thrown.

Any ideas?

Here's the code (apologies about lots of indentation):

    public void Foo(IEnumerable<FogbugzCase> cases)
    {
        using (SqlConnection conn = CreateConnection())
        {
            TruncateWorkingTable(conn, "Cases");

            foreach (FogbugzCase fogbugzCase in cases)
            {
                int categoryId = fogbugzCase.Category.Id;
                int? assigneeId = null;
                if (fogbugzCase.PersonAssignedTo != null)
                    assigneeId = fogbugzCase.PersonAssignedTo.Id;
                int? resolveeId = null;
                if (fogbugzCase.PersonResolvedBy != null)
                    resolveeId = fogbugzCase.PersonResolvedBy.Id;

                var args = new
                    {
                        BugId = fogbugzCase.BugId,
                        Title = fogbugzCase.Title,
                        ProjectId = fogbugzCase.Project.Id,
                        CategoryId = categoryId,
                        RootId = fogbugzCase.Root,
                        MilestoneId = fogbugzCase.Milestone.Id,
                        Priority = fogbugzCase.Priority,
                        StatusId = fogbugzCase.Status.Id,
                        EstimatedHours = fogbugzCase.EstimatedHours,
                        ElapsedHours = fogbugzCase.ElapsedHours,
                        PersonAssignedToId = assigneeId,
                        PersonResolvedById = resolveeId,
                        IsResolved = fogbugzCase.IsResolved,
                        IsOpen = fogbugzCase.IsOpen,
                        Opened = fogbugzCase.Opened,
                        Resolved = fogbugzCase.Resolved,
                        Uri = fogbugzCase.Uri,
                        OutlineUri = fogbugzCase.OutlineUri,
                        Spec = fogbugzCase.Spec,
                        ParentId = fogbugzCase.ParentId,
                        Backlog = fogbugzCase.Backlog
                    };
                conn.Execute("INSERT INTO fogbugz.Cases(CaseId, Title, ProjectId, CategoryId, Root, MilestoneId, Priority, Status, " +
                             "EstimatedHours, ElapsedHours, AssignedTo, ResolvedBy, IsResolved, IsOpen, Opened, Resolved, Uri, ResolveUri, " +
                             "OutlineUri, SpecUri, ParentId, Backlog) " +
                             "VALUES(@BugId, @Title, @ProjectId, @CategoryId, @RootId, @MilestoneId, @Priority, @StatusId, @EstimatedHours, " +
                             "@ElapsedHours, @PersonAssignedToId, @PersonResolvedById, @IsResolved, @IsOpen, @Opened, @Resolved, @Uri, " +
                             "@ResolveUri, @OutlineUri, @Spec, @ParentId, @Backlog);", 
                             args);
            }
        }
    }

Indeed, there is no inbuilt handling of Uri. Just use your chosen Uri-to-string representation (there are several and they behave differently) - for example:

...
OutlineUri = fogbugzCase.OutlineUri.OriginalString
...

This is something that perhaps we could do automatically - but simply it has never come up as a request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM