LINQ查询联接 [英] LINQ query Joins

查看:123
本文介绍了LINQ查询联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



When i use the below code to retrieve information, it shows an error..

var mails = from m in entity.mailboxes
            join p in entity.ordinary_user_profile_info on m.from_id equals p.user_id
            select new MailList
            {
                mid = m.m_id,
                mfrom = m.**from_id,** // Error occours here
                mfomname = p.username,
                msubject = m.subject
            };

错误是:

Error is:


int?mailbox.from_id

"int? mailbox.from_id "

不能将类型'int?'隐式转换为'int'。显式转换存在(您是否缺少演员?)

Cannot implicitly convert type 'int?' to 'int'. An explicit conversion exists (are you missing a cast?)

我声明了 m_id from_id 作为数据库中的int以及MailList类中的数据。

I have declared m_id and from_id as int in DB as well as in MailList class.

推荐答案

var mails = from m in entity.mailboxes
            join p in entity.ordinary_user_profile_info on m.from_id equals p.user_id
            select new MailList
            {
                mid = m.m_id,
                mfrom = m.from_id ?? 0,
                mfomname = p.username,
                msubject = m.subject
            };

这篇关于LINQ查询联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆