我使用Xamarin Forms和Sqlite开发应用程序。 我使用以下小块:
我想用sql创建查询。
我有两个表:
CREATE TABLE `AuditFormDto` (
`AuditDtoGuid` varchar,
`Id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
`Guid` varchar,
`AuditFormTradePointDtoId` integer,
`CreationLocationJson` varchar,
`CompletionLocationJson` varchar,
`CreationDate` bigint,
`CompletionDate` bigint,
`Status` integer,
`PlaceInAudit` integer,
`CreatorId` varchar,
`ServerId` integer,
`AuditServerId` integer,
`ShouldSync` integer,
`Deleted` integer
);
和
CREATE TABLE `AuditDto` (
`CreatorId` varchar,
`RegularQuestionIdsBlobbed` varchar,
`CreationLocationJson` varchar,
`CompletionLocationJson` varchar,
`Guid` varchar NOT NULL,
`DateCreated` bigint,
`DateFinished` bigint,
`Name` varchar,
`Comment` varchar,
`Type` integer,
`Status` integer,
`ServerId` integer,
`ShouldSync` integer,
PRIMARY KEY(`Guid`)
);
我还创建了包装器类
public class JoinedClass
{
public string AuditDtoGuid { get; set; }
public int Id { get; set; }
public int Type { get; set; }
public string Guid { get; set; }
}
但是当我尝试执行此代码时:
public async Task<JoinedClass> Get(int id)
{
var strQuery = $"SELECT * FROM AuditFormDto INNER JOIN AuditDto ON AuditDto.Guid = AuditFormDto.AuditDtoGuid where AuditFormDto.Id = {id}";
var joinedClass = await _connection.ExecuteScalarAsync<JoinedClass>(strQuery);
return joinedClass;
}
我有这个例外:
System.NotSupportedException: Don't know how to read JoinedClass
答案 0 :(得分:2)
ExecuteScalarAsync
返回有效计数而不是行结果。
您可以使用QueryAsync
进行更改。
它看起来像:
public async Task<IEnumerable<JoinedClass>> Get(int id)
{
var strQuery = $"SELECT * FROM AuditFormDto INNER JOIN AuditDto ON AuditDto.Guid = AuditFormDto.AuditDtoGuid where AuditFormDto.Id = {id}";
var joinedClass = await _connection.QueryAsync<JoinedClass>(strQuery);
return joinedClass;
}