Question

I allowed the WAMS wizard to create the "test" table ("Items") it so congenially offers to create after setting up my WAMS.

Then I wanted to create a table that will actually be useful to me. The instructions in the wizard do say, "You can add and remove tables later by using the "Data" tab above."

So I did that, and I did create a table, but I can't see now where I can change the structure of the table (IOW, add columns). I've tried 2-clicking the service, 2-clicking the table, selecting the "New" button, right-clicking on the sole column name (id) in my table, etc., but all to no avail.

Something I'm confused about, too, is the relationship of the tables I create this way with my existing SQL DB tables - or can I do without that SQL DB now (once I get these WAMSical tables set up)?

Or why can't I associate my existing SQL DB tables to my WAMS? And if I can -- how?

UPDATE

Also, it seems there is a mismatch between what is written and what I'm actually experiencing. This (from http://msdn.microsoft.com/en-us/magazine/jj721590.aspx) is not true/did not happen for me:

"2.Create a relational table to store your data. When you click on the Create TodoItem Table button, the wizard will automatically create a table based on the Windows Azure SQL Database you created (or re-used) previously."

I tried "from scratch," creating a new WAMS. Again, I get when I select my existing SQL DB, "Database and Mobile Service Not in the Same Region - Performance will decrease...Additionally, the data sent from the db to the mobile service will be counted as billable bandwidth usage. We recommend that you choose a database in the same location as the mobile service."

I would like to, but how? Why didn't WAMS adjust this for me automatically - or at least give me the option to put my DB and Mobile Service in the same place?

UPDATE 2

What is interesting is that I CAN see the new tables in LINQPad. I already had two SQL DB tables that display under that connection info, but on the same level as those tables is my WAMS name, under which are the "default" Items table and one of my own I created (both of which, though, only have one column, specifically "Id (Int64)"

IOW, what I see in LINQPad is:

blaBlaBla.database.windows.net,1433.blaBla
BlaBla
    BlaBlaSQLDB_Table1
    BlaBlaSQLDB_Table2
    wamsName
        Items
            Id (Int64)
        BlaBlaWAMSTable
            Id (Int64)

...so how do I extend/manage the "BlaBlaWAMSTable" is the problem now...

UPDATE 3

Well, looky here; LINQPad to the rescue again:

select * from <WAMSName>.<TableName>

...shows there is a record after I created the table I wanted via a class in my project (NOT in the Azure/WAMS management area)

...and, of course, LINQPad shows the newly added columns added that way.

All I needed to do was follow the steps provided (Reference the Azure SDK, add a corresponding using clause, etc.) and then added this method to test it out:

private async void InsertTestRecordIntoWAMSSQLDBTable()
{
    <WAMS Table class name> invitation = new <WAMS Table class name> { SenderID = "donkeyKongSioux@supermax.gov", ReaderDeviceID = "00-AA-11-BB-01-AB-10-BA", ReaderName = "B. Clay Shannon", SenderUTCOffset = 5, SenderDeviceID = "BA-10-AB-01-BB-11-AA-00" };
    await App.MobileService.GetTable<<WAMS Table class name>>().InsertAsync(invitation);
}

...and it worked. Now it would be nice to have some samples/examples for select queries as well as updates.

And my big remaining question (so far): can I decorate/annotate the columns/members of my table class? IOW, can I change this:

public class { public int Id { get; set; } public string SenderID { get; set; } public string ReaderDeviceID { get; set; } public string ReaderName { get; set; } public int SenderUTCOffset { get; set; } public string SenderDeviceID { get; set; } }

...to something like this:

public class { [Primary, AutoInc] public int Id { get; set; } [Indexed] public string SenderID { get; set; } [Unique] public string ReaderDeviceID { get; set; } [MaxLength(255)] public string ReaderName { get; set; } public int SenderUTCOffset { get; set; } public string SenderDeviceID { get; set; } }

?

I can't do exactly that, as those are SQLite annotations, but since I am unable to manage my table from the Azure/WAMS portal, how can I designate these attributes?

After altering the design of the table in code, I'm able to see that those columns have been added to my table in the WAMS portal, but it seems the only thing I can do to the columns is add an index...

UPDATE 4

It turns out that creating tables in WAMS is as easy as pie (but not as easy as pi/as hard as pi) - once you know how to do it.

With the WAMS created, select Data, and then Create to create a table. Give it a name, and select the permissions you want. This will give you a deadly dull but "living" database table with one, count 'em, one, column: ID, a BigInt, indexed.

THEN, to actually add more columns to the table, the easiest way I've found (the only way I've found that is, and it is easy) is to:

1) Create a class that corresponds to the database table, a la SQLite, such as:

public class WAMS_DUCKBILL
{
    public int Id { get; set; }
    public string PlatypusID { get; set; }
    public DateTime UpdateTimeUTC { get; set; }
    public double Income { get; set; }
    public double Outgo { get; set; }
}

2) Write a method that will add a record to this table, such as:

        private async void InsertTestRecordIntoWAMSDuckbillTable()
        {
            WAMS_DUCKBILL duckbill = new WAMS_DUCKBILL { PlatypusID = "42", UpdateTimeUTC =     
DateTime.Now, Income = 3.85, Outgo = 8311.79 };
            await MobileService.GetTable<WAMS_DUCKBILL>().InsertAsync(duckbill);
        }

3) Call that method from App.xaml.cs' OnLaunched event

4) As can then be seen by running the following query in LINQPad (or however you want to pee[k,r] into the database):

SELECT * FROM platypi.WAMS_DUCKBILL

Call me old fashioned, but notice I'm using tired old SQL as opposed to LINQ here; so sue me. At any rate, LINQPad shows that the test record has indeed been inserted into the WAMS table. Voila! as the escargot-eating, beret-at-a-rakish-angle wearing cats say.

Was it helpful?

Solution

The focus for Windows Azure Mobile Services (WAMS) are app developers who does not want to invest a lot of time to develop a backend. Therefor the data model easier than you might think.

Tables in WAMS are always backed by tables in a SQL database. You can create and delete tables via the portal.

Creating columns is a bit different. You create columns by simply using them. As soon as you write data for a column that does not exist, WAMS creates that column automatically. That's called Dynamic Schema. After development you should disable Dynamic Schema. You find it in the Mobile Service, Configure.

Documentation: Data access in Windows Azure Mobile Services

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top