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

選択的なプロパティに Select を使用しており、DTO でグループ化されているため、Fetch を使用する必要はないと思います。

        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 に答える