带有 SQLite 和 C# 错误“提供给命令的参数不足"的 Dapper [英] Dapper with SQLite and C# Error "Insufficient parameters supplied to the command"

查看:30
本文介绍了带有 SQLite 和 C# 错误“提供给命令的参数不足"的 Dapper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自原始帖子以来的新信息.这段代码成功检索了一个实体,这让我觉得 QueryMultiple 映射与 Query 不同.是真的吗?

New Information since the original post. This code successfully retrieves an entity, which makes me think QueryMultiple maps differently than Query. Is that true?

 using (var multi = sqlConn.QueryMultiple(sqlStmt, new { MytableId = mytableinstance.MytableId }))
 {
    var fullEnt = multi.Read<MytableSource>();
 }

<小时>

我想做的是使用Dapper根据父表的FK列值查询子表,以SQLite为数据库.下面的代码给了我错误


What I want to do is use Dapper to query a child table based on the FK column value of the parent, with SQLite as the database. The below code gives me the error

提供给命令的参数不足

有人能指出我的错误吗?

Could anyone point me to my error?

注意 - 我也在使用 Dapper.Contrib..NET 框架 4.7.2.

谢谢.

PRAGMA foreign_keys = '1';

CREATE TABLE "Mytable" (
    "MytableId" INTEGER Primary Key AutoIncrement,
    "MytableName"   TEXT UNIQUE,
    "Stamp" TEXT 
);


CREATE TABLE "MytableSource" (
    "MytableSourceId"   INTEGER Primary Key AutoIncrement,
    "MytableId" INTEGER,
    "SourceBlob"    BLOB,
    "Stamp" TEXT,
    FOREIGN KEY("MytableId") REFERENCES "Mytable"("MytableId")

);

<小时>

    [Table("Mytable")]
    public class Mytable
    {
        [Key]
        public long MytableId { get; set; }

        public String MytableName { get; set; }

        public String Stamp { get; set; }
    }

    [Table("MytableSource")]
    public class MytableSource
    {
        [Key]
        public long MytableSourceId { get; set; }

        public long MytableId { get; set; }

        public String SourceBlob { get; set; }

        public String Stamp { get; set; }
    }

<小时>

    var sqlStmt = "Select * From MytableSource Where MytableId = @MytableId";
                var sqlConn = new SQLiteConnection( this.ConnectionString );
                using ( sqlConn )
                {
                    sqlConn.Open();
                    var fullEnt = sqlConn.Query<MytableSource>(sqlStmt, new SQLiteParameter("@MytableId" , mytableinstance.MytableId )).FirstOrDefault();
                    this.MytableSourceCurrent = fullEnt;

                }

未知错误提供给命令的参数不足

unknown error Insufficient parameters supplied to the command

推荐答案

我从 GitHub 上查看了原始代码,搜索了 Query<T > 并仅通过几种方法手动跟踪.尽管它高度抽象且文档稀少,但代码本身至少表明需要一个 IEnumerable 对象.它似乎更喜欢将 Dapper.IDynamicParameters 对象用于集合,但除此之外,不值得费力地浏览代码以获取更多详细信息.

I looked at the original code from GitHub, searched for Query< T > and manually traced through only a few methods. Although it's highly abstract and documentation is sparse, the code itself at least reveals that an IEnumerable object is expected. It seems to prefer the Dapper.IDynamicParameters object for the collection, but beyond that it wasn't worth trudging through the code to get more details.

这在测试中对我有用:

var parameters = new DynamicParameters();
param.Add("@MytableId" , mytableinstance.MytableId);
var fullEnt = sqlConn.Query<MytableSource>(sqlStmt, parameters ).FirstOrDefault();

这篇关于带有 SQLite 和 C# 错误“提供给命令的参数不足"的 Dapper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆