您好,我正在嘗試使用Azure移動應用中的實體框架工作來獲取關係數據。如何從azure移動應用獲取關係數據
this tutorial中的信息談論了很多關於格式化的內容,而不是關於關係。 This one具有使用實體框架的相關數據,但沒有任何關於天藍色的移動應用程序。在這種情況下,他們使用ASP.net核心。我怎樣才能把兩者的信息放在一起?
我試圖以類似的方式建立關係,但它根本不承認關係。有人知道該怎麼做嗎?
更新 以下建議我設法讓外鍵顯示在遷移中,所以。
實體的定義如下
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; }
}
我懷疑我不需要虛擬屬性,但我會留下來,因爲在他們那裏的客戶端。
遷移顯示方面外鍵
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);
的正確關係但是發出請求表API時,結果仍然是
{"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"}
不包括相關的實體。
嘿。從我的理解應該工作,這就是我所做的。兩件事情,但你能寫出答案來顯示實際的代碼嗎?只是爲了確保我不會錯過任何東西。此外,這是如何解釋延遲加載,急切加載等從我讀你必須自己處理。 – xerotolerant
另外我檢查了我的migrations文件,出於某種原因,那裏確實沒有任何內容。我的數據庫有數據,我的種子方法工作正常,但是我的initialCreate遷移文件是空的,除了空的上下方法的類。 – xerotolerant
我添加了顯示兩個示例模型的代碼。 – Kenny