ORM select id always 0

 public class USession : AuthUserSession
    {
        public ILog Log { get; set; } = LogManager.GetLogger(typeof(USession));

        public override void OnRegistered(IRequest httpReq, IAuthSession session, IServiceBase service)
        {
            int id = 0;
            using (var db = httpReq.TryResolve<IDbConnectionFactory>().Open())
            {
                UserInfo u = new UserInfo();
                u.UserAuthId = session.UserAuthId.ToInt();
                u.Money = 0m;
               id  = (int)db.Insert(u,true);
                Log.Debug(u.Dump());
            }


            using (var db = httpReq.TryResolve<IDbConnectionFactory>().Open())
            {
             
               var  u = db.LoadSelect<UserInfo>(x => x.Id == id);
                Log.Debug(u.Dump());// UserInfo.id =0

                u = db.Select<UserInfo>(x => x.Id == id);
                Log.Debug(u.Dump());// UserInfo.id =0
            }
        }
    }

   public class UserInfo : IHasIntId
    {
        [AutoIncrement]
        public int Id { get; }

        [References(typeof(UserAuth))]
        public int UserAuthId { get; set; }
        [Reference]
        public UserAuth UserAuth { get; set; }
        [DecimalLength(18,2)]
        public  decimal Money { get; set; }
        public string SFZ { get; set; }
        public string ZFB { get; set; }
        public string QQ { get; set; }

    }

12-21 09:30:36|DEBUG|USession|{
	Id: 0,
	UserAuthId: 12,
	Money: 0
}
12-21 09:30:36|DEBUG|OrmLiteReadCommandExtensions|SQL: SELECT "Id", "UserAuthId", "Money", "SFZ", "ZFB", "QQ" 
FROM "UserInfo"
WHERE ("Id" = @0)
PARAMS: @0=1
12-21 09:30:36|DEBUG|OrmLiteReadCommandExtensions|SQL: SELECT "Id", "UserName", "Email", "PrimaryEmail", "PhoneNumber", "FirstName", "LastName", "DisplayName", "Company", "BirthDate", "BirthDateRaw", "Address", "Address2", "City", "State", "Country", "Culture", "FullName", "Gender", "Language", "MailAddress", "Nickname", "PostalCode", "TimeZone", "Salt", "PasswordHash", "DigestHa1Hash", "Roles", "Permissions", "CreatedDate", "ModifiedDate", "InvalidLoginAttempts", "LastLoginAttempt", "LockedDate", "RecoveryToken", "RefId", "RefIdStr", "Meta" FROM "UserAuth" WHERE "Id" IN (SELECT "UserInfo"."UserAuthId" 
FROM "UserInfo"
WHERE ("Id" = @0))
PARAMS: @0=1
12-21 09:30:36|DEBUG|USession|[
	{
		Id: 0,
		UserAuthId: 12,
		UserAuth: 
		{
			Id: 12,
			UserName: qwew123,
			FirstName: qwew123,
			LastName: qwew123,
			DisplayName: qwew123,
			PasswordHash: qwewsdas123,
			DigestHa1Hash: 4adba14e7952002433856497334217f0,
			Roles: [],
			Permissions: [],
			CreatedDate: 2016-12-21T09:30:36.6226258+08:00,
			ModifiedDate: 2016-12-21T09:30:36.6226258+08:00,
			InvalidLoginAttempts: 0
		},
		Money: 0
	}
]
12-21 09:30:36|DEBUG|OrmLiteReadCommandExtensions|SQL: SELECT "Id", "UserAuthId", "Money", "SFZ", "ZFB", "QQ" 
FROM "UserInfo"
WHERE ("Id" = @0)
PARAMS: @0=1
12-21 09:30:36|DEBUG|USession|[
	{
		Id: 0,
		UserAuthId: 12,
		Money: 0
	}
]

envirment: latest SS sqlite
when I dump the UserInfo UserInfo.id always 0 how should I do to get the right result

public class UserInfo : IHasIntId
{
        [AutoIncrement]
        public int Id { get; }
...

Your Id has no public set; so you are always getting the default value when the POCO is populated would be my guess. Try public int Id { get;set; }.

1 Like

oh yes I forget set public set thank you