user3597184
user3597184

Reputation: 13

New table Mobile Service Azure, can't get data

How can I add additional tables in azure mobile services and programmatically insert and read data. I tried doing it similarly as the code from TodoItems table. My new table is created and I can insert data manually by using sql, but when I use

private MobileServiceCollection<User,User> users;
private IMobileServiceTable<User> userTable = App.MobileService.GetTable<User>();

and

users = await userTable.ToCollectionAsync();

I get

if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();

Do you have any ideas how I can do it?

Upvotes: 0

Views: 605

Answers (2)

Glenn Gailey - MSFT
Glenn Gailey - MSFT

Reputation: 91

As Matt points out, to add a table to a .NET backend, you just add a new property to the Code First data model that returns a DbSet based on a new model data type (which inherits from the EntityData type).

Make sure that you also read the topic How to make data model changes to a .NET backend mobile service to learn about what happens when you try to change the data model of a .NET backend mobile service.

Upvotes: 0

Matt Milner
Matt Milner

Reputation: 825

If you are using the .NET backend you'll need to do the following:

  1. Create a new entity that represents the item in your table. Be sure you use the right base class.
  2. Add a new TableController to the controllers folder and select your new entity class and your EF context class in the wizard.

This should provide the API you need and automatically add the DBset property to the ef context for you. Don't forget to publish your application to Azure if you are testing against the deployed version and not the local version.

If you can provide more details on the exception you get when you hit that breakpoint, it would help. Check the locals window in Visual Studio or examine the arguments to the current method.

Upvotes: 2

Related Questions