尝试左连接 2 个表
public IEnumerable<APPLICANT> GetApplicant()
{
IEnumerable<APPLICANT> applicantdata = Cache.Get("applicants") as IEnumerable<APPLICANT>;
if (applicantdata == null)
{
var applicantList = (from a in context.Profiles
join app in context.APPLICANTs
on a.PROFILE_ID equals app.Profile_id into joined
from j in joined.DefaultIfEmpty()
select new
{
Profiles = a,
APPLICANTs= j,
}).Take(1000);
applicantdata = applicantList.AsQueryable().OrderBy(v => v.APPLICANT_ID).ToList();
if (applicantdata.Any())
{
Cache.Set("applicants", applicantdata, 30);
}
}
return applicantdata;
}
但问题是我在最后一行有错误
applicantdata = applicantList.AsQueryable().OrderBy(v => v.APPLICANT_ID).ToList();
错误说
错误 1 无法将类型“
System.Collections.Generic.List<AnonymousType#1>
”隐式转换为“System.Collections.Generic.IEnumerable<Models.APPLICANT>
”。存在显式转换(您是否缺少演员表)
这是我的申请者课程
[DataContract(IsReference = true)]
public partial class APPLICANT
{
[DataMember]
public int APPLICANT_ID { get; set; }
[DataMember]
public string APPLICANT_LastName { get; set; }
[DataMember]
public string APPLICANT_FirstName { get; set; }
[DataMember]
public string APPLICANT_MiddleName { get; set; }
[DataMember]
public string APPLICANT_Address { get; set; }
[DataMember]
public string APPLICANT_City { get; set; }
[DataMember]
public string APPLICANT_Phone { get; set; }
[DataMember]
public string APPLICANT_Email { get; set; }
[DataMember]
public Nullable<int> Profile_id { get; set; }