API - Entity Framework Core 2.1 возвращает дочернюю информацию

#include <time.h>
#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main ()
{
  time_t rawtime;
  struct tm * timeinfo;
  int year, month ,day;
  char str[256];

  cout << "Inter date: " << endl; 
  cin.getline(str,sizeof(str));

  replace( str, str+strlen(str), '/', ' ' );  
  istringstream( str ) >> day >> month >> year;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  timeinfo->tm_year = year - 1900;
  timeinfo->tm_mon = month - 1;
  timeinfo->tm_mday = day;
  mktime ( timeinfo );

  strftime ( str, sizeof(str), "%A", timeinfo );
  cout << str << endl;
  system("pause");
  return 0;
}
0
задан Paul 27 February 2019 в 16:45
поделиться

2 ответа

Вот пример явного кодирования, который я получил для работы:

  [HttpGet]
    public IEnumerable<TestInfo> GetTestInfo()
    {

       List<TestInfo> tstinfoIn = _context.TestInfo.ToList();
       List<TestTypeInfo> tsttypinfoIn = _context.TestTypeInfo.ToList();
       List<TestInfo> tstinfoComboOut = new List<TestInfo>();

       tstinfoComboOut = tstinfoIn
                       .Select(c => new TestInfo()
                       {
                           TestId = c.TestId,
                           TestShortDescription = c.TestShortDescription,
                           TestLongDescription = c.TestLongDescription,
                           TestTypeId = c.TestTypeId,
                           TestLimitsId = c.TestLimitsId,
                           TestTypeInfos = GetTestTypeInfo(tsttypinfoIn, c.TestTypeId)
                       })
                       .ToList();

        return tstinfoComboOut; 
    }

Вот метод GetTestTypeInfo для извлечения потомков:

 public static List<TestTypeInfo> GetTestTypeInfo(List<TestTypeInfo> tsttypinfoIn, int parentTestTypeId)
    {
        return tsttypinfoIn
                .Where(c => c.TestTypeId == parentTestTypeId)
                .Select(c => new TestTypeInfo
                {
                    TestTypeId = c.TestTypeId,
                    TestTypeShortDescription= c.TestTypeShortDescription,
                    TestTypeLongDescription = c.TestTypeLongDescription
                })
                .ToList();
    }

Пожалуйста, дайте мне знать, если есть лучший способ сделать это ...

0
ответ дан Paul 27 February 2019 в 16:45
поделиться

Обновленный ответ на основе вашей дополнительной информации.

[HttpGet]
public IEnumerable<TestInfo> GetTestInfo()
{
    return _context.TestInfo
        .Select(c => new TestInfo()
        {
            TestId = c.TestId,
            TestShortDescription = c.TestShortDescription,
            TestLongDescription = c.TestLongDescription,
            TestTypeId = c.TestTypeId,
            TestLimitsId = c.TestLimitsId,
            TestTypeInfos = c.TestTypeInfos.Where(x => x.TestTypeId == c.TestTypeId).ToList()
        })
        .ToList();
}
0
ответ дан Maxinoume 27 February 2019 в 16:45
поделиться
Другие вопросы по тегам:

Похожие вопросы: