I have two tables: User and UserType:
CREATE TABLE [dbo].[User](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
[UserTypeId] [int] NOT NULL
)
CREATE TABLE [dbo].[UserType](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL
)
My model classes:
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public UserType UserType { get; set; }
}
public class UserType
{
public int Id { get; set; }
public string Name { get; set; }
}
My query:
SELECT
U.Id
, U.Name
, UT.Id AS [UserTypeId]
, UT.Name AS [UserTypeName]
FROM dbo.User AS F
INNER JOIN dbo.UserType AS UT ON U.UserTypeId = UT.Id
ORDER BY U.Id
And my mapper class:
public class UserMapper : CrudEntityMapper<User>
{
public UserMapper() : base("User")
{
Property(x => x.UserType)
.ColumnName("UserTypeId")
.ToPropertyValue((x) => new UserType { Id = (int)x });
Property(x => x.UserType)
.ColumnName("UserTypeName")
.ToPropertyValue((x) => new UserType { Name = (string)x });
}
}
when i try to execute command i get list of users without userType.Id (Id always = 0). I need to fill with data my User and child UserType classes.
Please show me what i'm doing wrong.
cmd.ToList<User>();
PS. im using Griffin.Framework for mapping