getting Userid of a user

Sonia Samimi asked on October 7, 2018 10:20

Hi guys; I need to get the userid of a user by this code: UserId = UserInfoProvider.GetUsers("asia_nationalcode Like N'%" + NationalCode + "%'", string.Empty ); It does'nt work correctly. please help me to get the UserID of a user in CMS_user table with that where condition.

Thank you in advance Sonia

Correct Answer

Michael Eustace answered on October 7, 2018 11:00

Hi Sonia,

You can use the following code to return the UserID of the first record matching your where condition:

int UserId = ValidationHelper.GetInteger(UserInfoProvider.GetUsers()
                                        .WhereLike("asia_nationalcode", "%" + NationalCode + "%")
                                        .Column("UserID")
                                        .TopN(1)
                                        .GetScalarResult<int>()
                                    , 0);

The query is wrapped in ValidationHelper.GetInteger() in case no result is returned from the query.

Hope this helps.

2 votesVote for this answer Unmark Correct answer

Recent Answers


Sonia Samimi answered on October 7, 2018 13:37

Thank you . :)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.