这是一个代码。我想要ID值是12位还是13位搜索,如果数据匹配则返回对象值,如果不匹配则返回null。
public MobilinkN get(ulong ID)
{
SubInfoNEntities robject = new SubInfoNEntities();
using (SubInfoNEntities entities = new SubInfoNEntities())
{
string scnic = ID.ToString();
if (scnic.Length == 13)
{
return entities.MobilinkNs.FirstOrDefault(e => e.CNIC == scnic);
}
else if(scnic.Length == 12)
{
return entities.MobilinkNs.FirstOrDefault(e => e.MSISDN ==scnic);
}
return entities.MobilinkNs.FirstOrDefault(e => e.MSISDN == scnic);
}
}