Hello I am trying to get relational data using entity frame work from an Azure mobile App.
The info in this tutorial talks a lot about formatting but not about relationships. This one Has related data using entity framework but nothing about azure mobile apps. In this case they use ASP.net Core. How can I put the information from the two together?
I attempted to set up relationships in a similar manner however it does not acknowledge the relationships at all. Does anybody know what to do?
Update Following advice I managed to get the foreign keys to show in the migration so.
The entity definitions are as follows
public class Member : EntityData
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public virtual ICollection<Subscription> Subscriptions { get; set; }
}
public class Subscription : EntityData
{
public string MemberId { get; set; }
public string ShopItemId { get; set; }
public virtual Member Member { get; set; }
public virtual ShopItem ShopItem { get; set; }
public int Quantity { get; set; }
}
public class ShopItem : EntityData
{
public decimal Price { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Note { get; set; }
}
I suspect that I do not need the virtual properties but I'll leave them in since they are there on the client side.
The migration shows the correct relationship in terms of foreign keys
CreateTable(
"dbo.Subscriptions",
c => new
{
Id = c.String(nullable: false, maxLength: 128,
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "Id")
},
}),
MemberId = c.String(maxLength: 128),
ShopItemId = c.String(maxLength: 128),
Quantity = c.Int(nullable: false),
Version = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion",
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "Version")
},
}),
CreatedAt = c.DateTimeOffset(nullable: false, precision: 7,
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "CreatedAt")
},
}),
UpdatedAt = c.DateTimeOffset(precision: 7,
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "UpdatedAt")
},
}),
Deleted = c.Boolean(nullable: false,
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "Deleted")
},
}),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.Members", t => t.MemberId)
.ForeignKey("dbo.ShopItems", t => t.ShopItemId)
.Index(t => t.MemberId)
.Index(t => t.ShopItemId)
.Index(t => t.CreatedAt, clustered: true);
However when making a request to the table api the result is still
{"deleted":false,"updatedAt":"2016-12-07T21:55:19.174Z","createdAt":"2016-12-07T21:55:19.128Z","version":"AAAAAAAAB/s=","id":"1","quantity":1,"shopItemId":"1","memberId":"1"}
which does not include the related entity.