0

我正在尝试使用 QueryOver 进行查询,并尝试通过获取进行一些转换。

但我遇到了错误

    HSPTransactionDto hspTransactionDto = null;
    var hspTransactionDtoList =
        Session.QueryOver<Transaction>()
            .Where(x => x.TransactionStatus == TransactionStatus.Draft)
            .Fetch(x => x.HealthServiceProvider).Eager
            .Fetch(x => x.HealthMaintenanceOrganization).Eager
            .SelectList(list => list
                                    .Select(x => x.Id).WithAlias(() => hspTransactionDto.Id)
                                    .Select(x => x.Version).WithAlias(() => hspTransactionDto.Version)
                                    .Select(x => x.HealthServiceProvider.Id).WithAlias(() => hspTransactionDto.HSPId)
                                    .Select(x => x.HealthServiceProvider.Name).WithAlias(() => hspTransactionDto.HSPName)
                                    .Select(x => x.HealthMaintenanceOrganization.Id).WithAlias(() => hspTransactionDto.HMOId)
                                    .Select(x => x.HealthMaintenanceOrganization.Name).WithAlias(() => hspTransactionDto.HMOName)
                                    .Select(x => x.HSPPatientCode).WithAlias(() => hspTransactionDto.HSPPatientCode)
                                    .Select(x => x.PatientFirstName).WithAlias(() => hspTransactionDto.PatientFirstName)
                                    .Select(x => x.PatientMiddleName).WithAlias(() => hspTransactionDto.PatientMiddleName)
                                    .Select(x => x.PatientLastName).WithAlias(() => hspTransactionDto.PatientLastName)
            )
            .TransformUsing(Transformers.AliasToBean<HSPTransactionDto>()).List<HSPTransactionDto>();
    return hspTransactionDtoList;

有人可以帮忙吗?

实际上找到了答案,只需要输入一些别名,所以我最终得到了

    HSPTransactionDto hspTransactionDto         = null;
    HealthMaintenanceOrganization hmoAlias      = null;
    HealthServiceProvider hspAlias              = null;
    var hspTransactionDtoList =
        Session.QueryOver<Transaction>()
            .Where(a => a.TransactionStatus == TransactionStatus.Draft)
            .Fetch(b => b.HealthServiceProvider).Eager
            .Fetch(c => c.HealthMaintenanceOrganization).Eager
            .JoinAlias(x=> x.HealthMaintenanceOrganization,() => hmoAlias)
            .JoinAlias(x => x.HealthServiceProvider, () => hspAlias)
            .SelectList(list => list
                                    .Select(x => x.Id).WithAlias(() => hspTransactionDto.Id)
                                    .Select(x => x.Version).WithAlias(() => hspTransactionDto.Version)
                                    .Select(x => hspAlias.Id).WithAlias(() => hspTransactionDto.HSPId)
                                    .Select(x => hspAlias.Name).WithAlias(() => hspTransactionDto.HSPName)
                                    .Select(x => hmoAlias.Id).WithAlias(() => hspTransactionDto.HMOId)
                                    .Select(x => hmoAlias.Name).WithAlias(() => hspTransactionDto.HMOName)
                                    .Select(x => x.HSPPatientCode).WithAlias(() => hspTransactionDto.HSPPatientCode)
                                    .Select(x => x.PatientFirstName).WithAlias(() => hspTransactionDto.PatientFirstName)
                                    .Select(x => x.PatientMiddleName).WithAlias(() => hspTransactionDto.PatientMiddleName)
                                    .Select(x => x.PatientLastName).WithAlias(() => hspTransactionDto.PatientLastName)
            )
            .TransformUsing(Transformers.AliasToBean<HSPTransactionDto>()).List<HSPTransactionDto>();
    return hspTransactionDtoList;

有人知道更清洁的方法吗?

4

1 回答 1

1

我认为您不需要使用 Fetch,因为您已将 Select 用于选择性属性,并且它与 DTO 分组:

        HSPTransactionDto hspTransactionDto         = null;
        HealthMaintenanceOrganization hmoAlias      = null;
        HealthServiceProvider hspAlias              = null;
        var hspTransactionDtoList =
            Session.QueryOver<Transaction>()
                .Where(a => a.TransactionStatus == TransactionStatus.Draft)
                .JoinAlias(x=> x.HealthMaintenanceOrganization,() => hmoAlias)
                .JoinAlias(x => x.HealthServiceProvider, () => hspAlias)
                .SelectList(list => list
                                        .Select(x => x.Id).WithAlias(() => hspTransactionDto.Id)
                                        .Select(x => x.Version).WithAlias(() => hspTransactionDto.Version)
                                        .Select(x => hspAlias.Id).WithAlias(() => hspTransactionDto.HSPId)
                                        .Select(x => hspAlias.Name).WithAlias(() => hspTransactionDto.HSPName)
                                        .Select(x => hmoAlias.Id).WithAlias(() => hspTransactionDto.HMOId)
                                        .Select(x => hmoAlias.Name).WithAlias(() => hspTransactionDto.HMOName)
                                        .Select(x => x.HSPPatientCode).WithAlias(() => hspTransactionDto.HSPPatientCode)
                                        .Select(x => x.PatientFirstName).WithAlias(() => hspTransactionDto.PatientFirstName)
                                        .Select(x => x.PatientMiddleName).WithAlias(() => hspTransactionDto.PatientMiddleName)
                                        .Select(x => x.PatientLastName).WithAlias(() => hspTransactionDto.PatientLastName)
                )
                .TransformUsing(Transformers.AliasToBean<HSPTransactionDto>()).List<HSPTransactionDto>();
        return hspTransactionDtoList;
于 2012-05-14T09:18:49.090 回答