I created my database by script, then used the scaffold command to create my classes in visual studio, I added a new partial class for an entity (User) in which I added some custom properties (this wont be on the database) whenever I run a Get to this entity, it throws the error Invalid column name for every custom property I set in my partial class.
Exception message: SqlException: Invalid column name 'ResidentialName'. Invalid column name 'UserDocumentCount'. Invalid column name 'UserPaymentCount'.
The partial class created from the database.
public partial class User
{
public User()
{
UserDocument = new HashSet<UserDocument>();
UserPayment = new HashSet<UserPayment>();
}
public int UserId { get; set; }
public string UserIdentityId { get; set; }
public int? ResidentialId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Telephone { get; set; }
public string Street { get; set; }
public string Number { get; set; }
public int Block { get; set; }
public int Lot { get; set; }
public bool Status { get; set; }
public DateTime RegistrationDate { get; set; }
public Residential Residential { get; set; }
public AspNetUsers UserIdentity { get; set; }
public ICollection<UserDocument> UserDocument { get; set; }
public ICollection<UserPayment> UserPayment { get; set; }
}
The partial class I added.
public partial class User
{
public string ResidentialName { get { return this.ResidentialId > 0 && this.Residential != null ? this.Residential.Name : String.Empty; } set { } }
public int UserDocumentCount { get { return this.UserDocument != null ? this.UserDocument.Count : 0; } set { } }
public int UserPaymentCount { get { return this.UserPayment != null ? this.UserPayment.Count : 0; } set { } }
public static async Task<List<User>> GetList(KaiozamaDevContext ctx)
{
return await ctx.User.ToListAsync();
}
public static async Task<User> GetItem(KaiozamaDevContext ctx, int Id)
{
return await ctx.User.SingleOrDefaultAsync(m => m.UserId == Id);
}
public static async Task<User> GetItem(KaiozamaDevContext ctx, string Id)
{
return await ctx.User.SingleOrDefaultAsync(m => m.UserIdentityId == Id);
}
}
The error is thrown on any of the Get methods from above.
Greetings!
Further technical details
EF Core version: 2.1.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio Community 2017 15.4.1