' Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException'发生在mscorlib.ni.dll但未在用户代码中处理

时间:2015-07-09 18:18:22

标签: c# azure windows-phone-8.1 azure-mobile-services

每当我尝试向Azure插入一些数据时,我的程序就会在这行代码中崩溃:

await App.MobileService.GetTable<Group>().InsertAsync(grp);

有以下例外:

Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll but was not handled in user code
Additional information: The request could not be completed.  (Bad Request)

视图模型:

public RelayCommand CreateGroup2
{
    get
    {
        return _createGroup ?? (_createGroup = new RelayCommand(async () =>
        {
            if (GroupName == null)
            {
                await _dialogService.ShowMessage("Group name cannot be blank!", "MissingFields");
                return;
            }                        

            Group grp = new Group()
            {
                GroupName = this.GroupName,
                Type = this.Type,
                PinnedGroups = "true"
            };

            var test = (await App.MobileService.GetTable<Group>().ToListAsync()).Count();
            await App.MobileService.GetTable<Group>().InsertAsync(grp);
            //await _groupsDataService.InsertItemAsync(grp);

            if (true)
            {
                await _dialogService.ShowMessage("Group has been created", "Success!.");
                _navigationService.NavigateTo("Grouped");                            
            }
            //else
            //{
                // await _dialogService.ShowMessage("Group not created.", "Error!");
            //}
        }));
    }
}

XAML:

<Grid>
    <TextBox Header="Name"
             x:Name="txtgpname"
             Grid.Row="1" 
             TextWrapping="Wrap" 
             PlaceholderText="Name" 
             Height="64" 
             Foreground="#FF72AA0F"  
             Margin="10,75.833,162,0" 
             RenderTransformOrigin="0.511,2.118"  
             Text="{Binding CreateGroup.GroupName, Mode=TwoWay}"
             GotFocus="txtgpname_focus" />

    <!--<TextBlock Grid.Row="1" TextWrapping="Wrap" Text="Name" FontFamily="Segoe UI Light" FontSize="20" Margin="10,72.833,-10,12.333" SelectionChanged="TextBlock_SelectionChanged"/>-->
    <!--<TextBlock Grid.Row="1" TextWrapping="Wrap" Text="Type" FontFamily="Segoe UI Light" FontSize="20" Margin="10,179.833,-10,98" Grid.RowSpan="2"/>-->
    <ComboBox x:Name="comboBox" 
              Header="Type" 
              Foreground="#FF72AA0F"  
              HorizontalAlignment="Left" 
              Margin="10,194.833,0,0" 
              Grid.Row="1" 
              VerticalAlignment="Top" 
              Width="228" 
              Height="160" 
              PlaceholderText="Type" 
              Grid.RowSpan="2" 
              Background="Green" 
              DataContext="{Binding CreateGroup.Type, Mode=TwoWay}">
        <x:String>Private</x:String>
        <x:String>Public</x:String>
    </ComboBox>
 </Grid>
 </PivotItem>
 </Pivot>
 </Grid>
 <AppBarButton Icon="Accept" Label="create" Name="done"  ClickMode="Press" Command="{Binding CreateGroup.CreateGroup2, Mode=TwoWay}" />

的DataModel:

public class Group : IBusinessEntityBase
{
    public string Id { get; set; }
    public string GroupName { get; set; }
    //public Boolean Type { get; set; }   //Either Public or Private
    public string Type { get; set; } 
    //public Boolean PinnedGroups { get; set; }
    public string PinnedGroups { get; set; }                               
    public string EventId { get; set; } //Inherit from Events class
}

0 个答案:

没有答案