相关疑难解决方法(0)

在ADO.NET中获取输出参数值

我的存储过程有一个输出参数:

@ID INT OUT
Run Code Online (Sandbox Code Playgroud)

如何使用ado.net检索此内容?

using (SqlConnection conn = new SqlConnection(...))
{
    SqlCommand cmd = new SqlCommand("sproc", conn);
    cmd.CommandType = CommandType.StoredProcedure;

    // add parameters

    conn.Open();

    // *** read output parameter here, how?
    conn.Close();
}
Run Code Online (Sandbox Code Playgroud)

.net c# ado.net

90
推荐指数
5
解决办法
19万
查看次数

精巧的多映射问题

继续运行"如果使用多映射API,请确保在下面的代码块中设置了除了Id之外的其他键的splitOn参数"错误:

var accounts = DbConnection.Query<Account, Branch, Application, Account>(
            "select Accounts.*, SplitAccount = '', Branches.*, SplitBranch = '', Applications.*" +
            " from Accounts" +
            "    join Branches" +
            "       on Accounts.BranchId = Branches.BranchId" +
            "    join Applications" +
            "       on Accounts.ApplicationId = Applications.ApplicationId" +
            " where Accounts.AccountId <> 0",
            (account, branch, application) =>
                {
                    account.Branch = branch;
                    account.Application = application;
                    return account;
                }, splitOn : "SplitAccount, SplitBranch"
            ).AsQueryable();
Run Code Online (Sandbox Code Playgroud)

我正在使用SplitAccount和SplitBranch for splitOn作为解决方法.

我错过了什么?

谢谢

编辑:

我已经清理了一下我的测试,下面是一个轻量级的类和一个新的查询:

public class AccountLight
{
    public int …
Run Code Online (Sandbox Code Playgroud)

dapper

12
推荐指数
1
解决办法
1万
查看次数

小巧玲珑的简单映射

表:

create table Documents 
   (Id int, 
    SomeText varchar(100), 
    CustomerId int, 
    CustomerName varchar(100)
   )

insert into Documents (Id, SomeText, CustomerId, CustomerName) 
   select 1, '1', 1, 'Name1' 
     union all
   select 2, '2', 2, 'Name2'
Run Code Online (Sandbox Code Playgroud)

类别:

public class Document
{
    public int Id { get; set; }
    public string SomeText { get; set; }
    public Customer { get; set; }
}

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我如何与Dapper Documents一起完成所有工作 …

c# sql-server orm dapper

5
推荐指数
1
解决办法
5423
查看次数

标签 统计

c# ×2

dapper ×2

.net ×1

ado.net ×1

orm ×1

sql-server ×1