代码改变世界

C#里System.Data.SQLite中对GUID的处理

2016-05-31 10:03  Dorisoy  阅读(1271)  评论(0编辑  收藏  举报
 string sqlstring = "select * from endpoint_policy where HEX([UserGuid]) ='" + CommonHelper.ConvertGuid(uguid) + "'";
 var query = db.Database.SqlQuery<endpoint_policy>(sqlstring).AsQueryable();
 var endpoint_policy = new PagedList<endpoint_policy>(query.OrderByDescending(c => c.CreatedOnUtc), pageIndex, pageSize);
public static string ConvertGuid(Guid gd)
{
            string sgd = gd.ToString().ToUpper();
            string sVar = "";
            int i;
            foreach (string sv in new string[] { sgd.Substring(0, 8), sgd.Substring(9, 4), sgd.Substring(14, 4) })
            {
                for (i = sv.Length - 2; i >= 0; i -= 2)
                {
                    sVar += sv.Substring(i, 2);
                }
            }
            sgd = sgd.Substring(19).Replace("-", "");
            for (i = 0; i < 8; i++)
            {
                sVar += sgd.Substring(2 * i, 2);
            }
            return sVar;
 }