3

i'am trying to perform a join between a revision entity from nhibernate envers and a list with user names. i want to return a list of named tuples.

this is my code

public IEnumerable<(Societa company, DateTime datetime, string userName)> CompanyHistory()
{
    IAuditReader auditReader = this._session.Auditer();
    var revison = auditReader.CreateQuery().ForHistoryOf<Societa, RevisionEntity>().Results();
    IList<Persona> user = _session.QueryOver<Persona>().List();

    var query = revison.Join(user,
                        rev => rev.RevisionEntity.IdUtente,
                        us => us.Id,
                        (rev, us) => new
                        {
                            Oggetto = rev.RevisionEntity,
                            DataModifica = rev.RevisionEntity.RevisionDate.ToLocalTime(),
                            NomeUtente = us.NomePersona
                        }).ToList();
}

but now i didn't find a way to return the tuple

  • cast didn't work
  • ToValueTuple is not avaible to fro my query object

i try also

(ele, p) => new (OutputGA Oggetto, DateTime DataModifica, string NomeUtente)
            {
                Oggetto = ele.RevisionEntity,
                DataModifica = ele.RevisionEntity.RevisionDate.ToLocalTime(),
                NomeUtente = p.NomePersona
            }).ToList();

but i got new cannot be used with tuple type

than

(ele, p) => new Tuple<OutputGA, DateTime, string>
            {
                Oggetto = ele.RevisionEntity,
                DataModifica = ele.RevisionEntity.RevisionDate.ToLocalTime(),
                NomeUtente = p.NomePersona
            }).ToList();

and got error about parameter not corresponding

Roman Koliada
  • 4,286
  • 2
  • 30
  • 59
gt.guybrush
  • 1,320
  • 3
  • 19
  • 48

2 Answers2

9

You can try this

var tuples = data.Select(x => (A: x.A, B: x.B));
Shantanu
  • 554
  • 2
  • 9
2

I think the correct syntax should be

(ele, p) => 
(
    Oggetto: ele.RevisionEntity,
    DataModifica: ele.RevisionEntity.RevisionDate.ToLocalTime(),
    NomeUtente: p.NomePersona
)).ToList();
Jay
  • 21
  • 2
  • in this way i get "The name Oggetto does not exist in the current context" and same for DataModifica and NomeUtente – gt.guybrush Jun 05 '19 at 10:39
  • I am not sure why you got this error. I guess it may be something related to the variable scope. As a reference, you may check the example I made on the [link](https://dotnetfiddle.net/qrRKBS) which should be able to compile with .NET Core 2.2. – Jay Jun 05 '19 at 12:18