Answer the question
In order to leave comments, you need to log in
Not loading property value in EF6. What is the problem?
Hello. Not long ago I started learning EF6. Here is an example:
DB Model.
public class User
{
public int Id {get;set;}
public string FirstName {get;set;}
public string SecondName {get;set;}
public DateTime DateOfBirth {get;set;}
public string Email {get;set;}
public string Password {get;set;}
public Token Token { get; set; }
}
public class Token
{
public int Id { get; set; }
public string UUID { get; set; }
public bool Status { get; set; }
}
public class DTBS : DbContext
{
public DTBS() : base("DBUsers")
{
base.Database.CreateIfNotExists();
}
public DbSet<User> Users { get; set; }
public DbSet<Token> Tokens { get; set; }
}
static void Main ( string[] args )
{
var db = new DTBS();
var user = db.Users.FirstOrDefault();
Console.Write(user.FirstName);
Console.ReadLine();
}
Answer the question
In order to leave comments, you need to log in
Correct the model:
public class User
{
public int Id {get;set;}
public string FirstName {get;set;}
public string SecondName {get;set;}
public DateTime DateOfBirth {get;set;}
public string Email {get;set;}
public string Password {get;set;}
public virtual Token Token { get; set; }
public int TokenId { get; set; }
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question