开发者

Call Method from Linq query

开发者 https://www.devze.com 2022-12-29 00:39 出处:网络
I am using Linq query and call method Like.. oPwd = objDecryptor.DecryptIt((c.Password.ToString()) it will return null value.

I am using Linq query and call method Like..

oPwd = objDecryptor.DecryptIt((c.Password.ToString())

it will return null value.

Means this will not working.

how I Resolve this.

Thanks..

var q =
    from s in db.User
    join c in db.EmailAccount on s.UserId equals c.UserId
    join d in db.POPSettings 
        on c.PopSettingId equals d.POPSettingsId
    where s.UserId == UserId && 开发者_开发百科c.EmailId == EmailId
    select new
    {
        oUserId = s.UserId,
        oUserName = s.Name,
        oEmailId = c.EmailId,
        oEmailAccId = c.EmailAccId,
        oPwd = objDecryptor.DecryptIt(c.Password.ToString()),
        oServerName = d.ServerName,
        oServerAdd = d.ServerAddress,
        oPOPSettingId = d.POPSettingsId,
    };


If that is LINQ-to-SQL or Entity Framework. You'll need to break it into steps (as it can't execute that at the DB). For example:

var q = from s in db.User
        join c in db.EmailAccount on s.UserId equals c.UserId
        join d in db.POPSettings on c.PopSettingId equals d.POPSettingsId
        where s.UserId == UserId && c.EmailId == EmailId
        select new
        {
            oUserId = s.UserId,
            oUserName = s.Name,
            oEmailId = c.EmailId,
            oEmailAccId = c.EmailAccId,
            oPwd = c.Password,
            oServerName = d.ServerName,
            oServerAdd = d.ServerAddress,
            oPOPSettingId = d.POPSettingsId,
        };

then use AsEnumerable() to break "composition" against the back-end store:

var query2 = from row in q.AsEnumerable()
        select new
        {
            row.oUserId,
            row.oUserName,
            row.oEmailId,
            row.oEmailAccId,
            oPwd = objDecryptor.DecryptIt(row.oPwd),
            row.oServerName,
            row.oServerAdd,
            row.oPOPSettingId
        };


var q = from s in db.User
    join c in db.EmailAccount on s.UserId equals c.UserId
    join d in db.POPSettings on c.PopSettingId equals d.POPSettingsId
    where s.UserId == UserId && c.EmailId == EmailId
    select new
    {
        oUserId = s.UserId,
        oUserName = s.Name,
        oEmailId = c.EmailId,
        oEmailAccId = c.EmailAccId,
        oPwd = c.Password,
        oServerName = d.ServerName,
        oServerAdd = d.ServerAddress,
        oPOPSettingId = d.POPSettingsId,
    };

foreach (var item in q)
        {
            item.oPwd = objDecryptor.DecryptIt(row.oPwd),
        }

we can use a foreach loop also to update a single property. do not need to select all property in next query.


This has nothing about Linq query. you need to debug method objDecryptor.DecryptIt

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号