I'm using EF and LINQ but it's slow.

I want to remake request to clean SQL, but have a problem.

For example, I have this request.

var request = await db.Journal.AsNoTracking().Where(x => x.userid == userId).Select(x => new Statistic
            {
                DoneAt = x.DoneAt,
                Description = x.Description,
                Procedures = x.Procedures.Select(a => new Procedures
                {
                    Name = a.Name,
                    Time = a.Time
                }).ToList()
            }).ToListAsync();

Two related tables Journal and Procedures. One record in Journal has relations with one or many records in Procedures. And it's easy to mapping it with EF. I receiving list of procedures for every record in journal. It's OK.

Next, I'm trying to remake this request to SQL and I'm using Join to receive results in one table. But I receiving a duplicates row when Procedures have more then one row. And it's OK. But it's no conveniently to work with it - need parse it and make it like it was when I use LINQ and EF (every Journal record has a list of procedures).Is there any other way or best practice or just retrieve this data and then convert it to Object?

Related posts

Recent Viewed