Hi, I'm currently learning how to use NPoco and I have a strange behavior, I can't figure out what am I doing wrong with this. Any help is greatly appreciated.
My database is designed like this :
Agency (Id, AgencyName)
User (Id, Name, Agency) where Agency column references Agency.Id
I made two classes:
Agency class
[TableName("Agency")]
[PrimaryKey("Id", AutoIncrement = true)]
class Agence
{
[Column]
public int Id { get; set; }
[Column(Name = "AgencyName")]
public string Name { get; set; }
}
User class
[TableName("User")]
[PrimaryKey("Id", AutoIncrement = true)]
[ExplicitColumns]
class User
{
[Column]
public int Id { get; set; }
[Column]
public string Name { get; set; }
[ComplexMapping]
[ResultColumn]
public Agency Agency { get; set; }
}
The only noticeable thing here is that the Name property in Agency class is not the same as the database field name (AgencyName).
I am retrieving a user this way:
User user = db.Single<User>(@"select [User].Name, [User].Id, [Agency].Id, [Agency].AgencyName
FROM [User], [Agency]
WHERE [User].Id = @0
AND [Agency].Id = [User].Agency", 1);
With this line of code, every members from User and Agency are properly populated with correct values except Name property from Agency class. It is always null.
It seems like I have two options to make the "Name" field properly filled :
Changing the "AgencyName" property to "Name" to make it same as Database column name
Adding "as Name" to [Agency].AgencyName field in the SQL Query
Those 2 ways are correctly filling the property with correct data, but in my understanding, I should not have to make those changes since I'm already adding [Column(Name = "AgencyName")] attribute to the property.
Hi, I'm currently learning how to use NPoco and I have a strange behavior, I can't figure out what am I doing wrong with this. Any help is greatly appreciated.
My database is designed like this :
Agency (Id, AgencyName) User (Id, Name, Agency) where Agency column references Agency.Id
I made two classes:
Agency class
User class
The only noticeable thing here is that the Name property in Agency class is not the same as the database field name (AgencyName).
I am retrieving a user this way:
With this line of code, every members from User and Agency are properly populated with correct values except Name property from Agency class. It is always null.
It seems like I have two options to make the "Name" field properly filled :
Those 2 ways are correctly filling the property with correct data, but in my understanding, I should not have to make those changes since I'm already adding
[Column(Name = "AgencyName")]
attribute to the property.Am I missing something?
Thank you very much for your help. Regards