[英]MobileServiceInvalidOperationException Xamarin.Forms connecting to Azure using LINQ
我有数据库天蓝色的表会议和会话。 会议有一个会议的外键。 在前端,我试图连接到该数据库并使用具有特定会议外键的会话,但是当我尝试执行此操作时,出现以下问题
我的代码:
// Return Sessions of the current conference
public async Task<ObservableCollection<Session>> GetSessionsAsync(Conference currentConference, bool syncItems = false)
{
try
{
IEnumerable<Session> sessions = await sessionTable
//problem is here .Where(s => s.ConferenceId == currentConference.Id)
.ToEnumerableAsync();
return new ObservableCollection<Session>(sessions);
}
catch (MobileServiceInvalidOperationException msioe)
{
Debug.WriteLine(@"MSIOE exception: {0}", msioe.Message);
}
catch (Exception e)
{
Debug.WriteLine(@"Some exception: {0}", e.Message);
}
return null;
}
最有趣的是,如果我写
Debug.WriteLine(sessions.First().ConferenceId == currentConference.Id);
在问题字符串之后(不使用LINQ“ Where”即可工作),它将显示为“ true”。
即使我在问题字符串之后使用linq表达式,它们也可以正常工作。 如果我不将where子句与ConferenceId
列一起使用,它也对我有用。
PS在调试窗口中,我看到了MSIOE异常
在执行Linq to Entities查询时,通常最好将查询本身中对属性访问器的使用减至最少。 尝试这个。
public async Task<ObservableCollection<Session>> GetSessionsAsync(Conference currentConference, bool syncItems = false)
{
try
{
var conferenceId = currentConference.Id;
IEnumerable<Session> sessions = await sessionTable
.Where(s => s.ConferenceId == conference.Id)
.ToEnumerableAsync();
return new ObservableCollection<Session>(sessions);
}
catch (MobileServiceInvalidOperationException msioe)
{
Debug.WriteLine(@"MSIOE exception: {0}", msioe.Message);
}
catch (Exception e)
{
Debug.WriteLine(@"Some exception: {0}", e.Message);
}
return null;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.