#c# #.net #entity-framework
#c# #.net #entity-framework
Вопрос:
У меня проблема: я видел другие сообщения здесь, но они, похоже, не работают.
У меня есть userClass
:
public class UserClass
{
public int Id { get; set; }
public int deskId { get; set; }
public int departmentId { get; set; }
public bool isManager { get; set; }
public int managerId { get; set; }
public string lastName { get; set; }
public string emailAdress { get; set; }
public string firstName { get; set; }
public Desk desk { get; set; }
}
Мой классный стол выглядит так
public class Desk
{
public int deskId { get; set; }
public int deskNumber { get; set; }
public int floorNumber { get; set; }
public bool isOffice { get; set; }
}
У меня есть хранимая процедура, в которой я вызываю все, но она возвращает desk как null. Не похоже, что Entity Framework распознает класс desk
.
Вот как выглядит мой DbContext
public DbSet<UserClass> UserClass { get; set; }
public DbSet<Desk> Desk { get; set; }
И это моя миграция
modelBuilder.Entity("UserService.Models.Desk", b =>
{
b.Property<int>("deskId")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<int>("deskNumber")
.HasColumnType("int");
b.Property<int>("floorNumber")
.HasColumnType("int");
b.Property<bool>("isOffice")
.HasColumnType("bit");
b.HasKey("deskId");
b.ToTable("Desk");
});
modelBuilder.Entity("UserService.Models.UserClass", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<int>("departmentId")
.HasColumnType("int");
b.Property<int?>("deskId")
.HasColumnType("int");
b.Property<string>("emailAdress")
.HasColumnType("nvarchar(max)");
b.Property<string>("firstName")
.HasColumnType("nvarchar(max)");
b.Property<bool>("isManager")
.HasColumnType("bit");
b.Property<string>("lastName")
.HasColumnType("nvarchar(max)");
b.Property<int>("managerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("departmentId");
b.HasIndex("deskId");
b.ToTable("UserClass");
});
modelBuilder.Entity("UserService.Models.UserClass", b =>
{
b.HasOne("UserService.Models.Desk", "desk")
.WithMany()
.HasForeignKey("deskId");
});
Нужно ли мне настраивать третью таблицу «объединения», как я видел примеры? Или я мог бы решить это любым другим способом?
Мне не нужна хранимая процедура, но я также пытался запросить саму userClass
таблицу
BR M.B
Комментарии:
1. не могли бы вы, пожалуйста, включить свой фактический код, а также основной класс DbContextConfiguration, а не код миграции?
2. Что возвращает хранимая процедура? Также покажите код, который вызывает sproc. Обратите внимание, однако, что sproc не является составным, что-то подобное
Include
невозможно.