您好,我正在尝试使用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