如何从IdentityUser .Include方法急切加载City

时间:2019-05-18 06:40:02

标签: asp.net entity-framework-6 asp.net-identity

我正在Asp.net MVC中的一个项目Wedding Hall网站上工作。我正在使用Asp.net Web API构建API。为了进行身份验证和授权,我使用的是Asp.net身份。我在课堂上学到了一些有关导航属性的知识,并且我试图加载城市课程信息。我遇到的问题是我无法使用.Include方法加载City。通过以下代码,我在city字段中得到了空值。

我尝试使用.include方法急切地加载city类,但该方法未显示。

let [block] = await this.models.Block.aggregate([
    {$match: filter},
    {
        $lookup: {
        from: 'headers',
        localField: 'hash',
        foreignField: 'hash',
        as: 'header'
    }
    },
    {$addFields: {header: {$arrayElemAt: ['$header', 0]}}}
])

1 个答案:

答案 0 :(得分:0)

导入System.Data.Entity命名空间:

#include <iostream>
#include <string>
using namespace std;

const int MAX_P = 200;
const int MAX_J = 30;

struct Personatge
{
int Numero;
string Nom;
char Tier;
float Pes;
};

struct Jugadors
{
string Username;
string Nom;
bool Amateur;
int PJfav;
};

int menu();
void altaJugador(Jugadors* jugs);

void main() {

Personatge vectorPersonajes[MAX_P];
Jugadors vectorJugadores[MAX_J];

int opcion = menu();

switch (opcion)
{
case 1: 
    altaJugador(vectorJugadores);
    break;
case 2:
    break;
case 3:

    break;
case 4: 
    break;
default:
    break;
}

system("pause");
}

int menu() {

int eleccion;

cout << "SSBU CEP Tournament \n";
cout <<
    "1. Alta jugador \n" <<
    "2. Establir personatge favorit \n" <<
    "3. Mostrar jugadors \n" <<
    "4. Baixa jugador \n" <<
    "5. Alta personatge (manual) \n" <<
    "6. Llistat de personatges d'un tier \n" <<
    "0. Sortir \n";
cout << "Opcio: \n";

do
{
    cin >> eleccion;
    if (eleccion < 0 || eleccion > 6)
    {
        cout << "Error, tria un numero del 0 al 6 \n";
    }
} while (eleccion < 0 || eleccion > 6);

return eleccion;
}
void altaJugador(Jugadors *jugs) {

cout << "Introduce el username del jugador: \n";
getline(cin, (jugs->Username));

cout << "Introduce el nombre y el apellido: \n";
getline(cin, (jugs->Nom));

cout << "Eres amateur? S/N: \n";
cin >> jugs->Amateur;

cout << "Introduce el numero de tu personaje favorito: \n";
cin >> jugs->PJfav;
}

导航属性必须定义为虚拟:

using System.Data.Entity;