I have a IQueryable method as below:
public IQueryable<vmTest> TestMethod(long ID)
{
return from m in db.table1
join n in db.table2
on m.table1_ID equals n.table1_ID into tabC
from c in tabC
join o in db.table3
on m.table3_ID equals o.table3_ID
where m.table1_ID.Equals(ID)
select new vmTest{ field1 = m.xxx };
}
from the code above, m.xxx is a long type and in the vmTest there is a public long field1. There is error with m.xxx which saying Cannot implicitly convert type 'long?' to 'long'.An explicit conversion exists (are you missing a cast?).May I know what's wrong?
Additional information:
If i cast (long) in front of m.xxx, error will be dissapear but another problem occur when this query returning no value as it's wrong to cast long to null
You have several solutions:
You can use a condition in your query like
new vmTest { field1 = m.xxx.HasValue ? m.xxx.Value : 0 }
More information on Nullables here
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加