sách gpt4 ai đã đi

Kiểu kết quả 'System.Tuple`3[System.Guid,System.Int32,System.String]' không được trừu tượng và phải chứa một hàm tạo mặc định

In lại 作者:行者123 更新时间:2023-11-30 22:51:36 34 4
mua khóa gpt4 Nike

是否可以从 ObjectContext 对象中读取元组列表?

我在存储过程中有类似这样的数据库查询

LỰA CHỌN 
T.Id as Item1, -- this is guid
T.WorkflowId AS Item2, -- this is int
T.ActionName AS Item3 -- this is string
FROM
MyTable T

C# 代码我试着这样读

var command = context.Database.Connection.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "[SEQUOIA].[GetWriteOffRequestDetails]";
var objectContext = ((IObjectContextAdapter)context);
context.Database.Connection.Open();

if (reader.NextResult())
{
// this line is giving error, so basically where it is trying to read/translate the result
List<>> requestItemActions = objectContext.ObjectContext.Translate<>>(reader).Select(x => new Tuple(x.Item1, x.Item2, x.Item3)).ToList();
}

但是它抛出了这个异常

The result type 'System.Tuple`3[System.Guid,System.Int32,System.String]' may not be abstract and must include a default constructor.

那么甚至可以像这样读取元组吗?

如果是,有人能指出我遗漏了什么吗?

1 Câu trả lời

在这种情况下你不能使用tuple bởi vìtuple lớp học没有默认构造函数(无参数构造函数).net 框架使用反射自动创建此类型,因此它应该有默认构造函数。

所以在这种情况下的解决方案是创建包含这三个属性的类并使用它而不是元组

public class DataClass
{

public Guid Item1 { get; set; }
public int Item2 { get; set; }
public string Item3 { get; set; }
}




List requestItemActions = objectContext.ObjectContext.Translate(reader).ToList();

关于c# - 结果类型 'System.Tuple` 3[System.Guid,System.Int32,System.String]' 可能不是抽象的,必须包含默认构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59031419/

34 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com