Imagine I have three classes like these :
public class Employee {
public int EmployeeId {get;set;}
public string Fname {get;set;}
public File Picture {get;set;}
}
public class Employer {
public int EmployerId {get;set;}
public string Fname {get;set;}
public string WorkingPlace{get;set;}
public File Pictrue {get;set;}
}
public class File {
public int FileId {get;set;}
public byte[] Content {get;set;}
public int Size {get;set;}
}
First, Is above code right way to save files and images of different entities? and then this is my context class:
public class MyDbContext : DbContext
{
public DbSet<File> Files { get; set; }
public DbSet<Employee> Employees { get; set; }
public DbSet<Employer> Employers { get; set; }
}
When I have query like this :
MyDbContext context = new MyDbContext
var q = from emp in context.Employees
where emp.EmployeeId == 4
select emp;
Console.WriteLine(q.First().Picture.FileId)
I get 0 as FileId while I see it's not 0 when I look in database.
Somehow q.First().Picture is not set correctly