Windows phone 8 在独立存储中存储自定义对象列表时出错
我有一个如下类型的自定义类Windows phone 8 在独立存储中存储自定义对象列表时出错,windows-phone-8,linq-to-sql,Windows Phone 8,Linq To Sql,我有一个如下类型的自定义类 [Table] class MyApp { public MyApp() : base() { } [Column(IsPrimaryKey=true, UpdateCheck = UpdateCheck.Never)] public string appCode { get; set; } [Column(UpdateCheck = UpdateCheck.Never)] public s
[Table]
class MyApp
{
public MyApp()
: base()
{
}
[Column(IsPrimaryKey=true, UpdateCheck = UpdateCheck.Never)]
public string appCode { get; set; }
[Column(UpdateCheck = UpdateCheck.Never)]
public string procCode { get; set; }
}
我还有一个类,其中包含MyApp对象列表,如下所示:
[Table]
class ApplicationUser
{
public ApplicationUser()
:base()
{
}
[Column(IsPrimaryKey = true, UpdateCheck = UpdateCheck.Never)]
public string userId { get; set; }
[Column(UpdateCheck = UpdateCheck.Never)]
public List<MyApp> applicationList { get; set; }
}
请指导我。因为我看到问题是
应用程序列表
标记了列
属性,尽管它表示一种关系
基本上,您必须使用EntityRef
和EntitySet
类以及关联
属性正确映射这些实体之间的关系
可能会有帮助
下面是更正映射(针对一对多关系)的示例:
已调整的ApplicationUser
class
[Table]
public class ApplicationUser
{
private EntitySet<MyApp> _userApplications = new EntitySet<MyApp>();
[Column(IsPrimaryKey = true, UpdateCheck = UpdateCheck.Never)]
public string UserId { get; set; }
[Association(Storage = "_userApplications", ThisKey = "UserId", OtherKey = "ApplicationUserId")]
public EntitySet<MyApp> ApplicationList
{
get { return _userApplications; }
set { _userApplications = value; }
}
}
[Table]
public class MyApp
{
private EntityRef<ApplicationUser> _applicationUserRef;
[Column(IsPrimaryKey = true, UpdateCheck = UpdateCheck.Never)]
public string AppCode { get; set; }
[Column(UpdateCheck = UpdateCheck.Never)]
public string ProcCode { get; set; }
[Column]
public string ApplicationUserId { get; set; }
[Association(Name = "FK_MyApp_ApplicationUser", Storage = "_applicationUserRef", ThisKey = "ApplicationUserId", OtherKey = "UserId")]
public ApplicationUser ApplicationUserReference
{
get { return _applicationUserRef.Entity; }
set { _applicationUserRef.Entity = value; }
}
}
检查一下-据我所知,
ApplicationUser
应该以一对多的方式与MyApp
关联,对吧?@danyloid是的。一个应用程序用户可以有多个应用程序。是否可能将一个应用程序分配给多个用户?是的,这是可能的。但是在移动设备上,假定只有一个用户。更正了applicationserid
propertyColumn
属性
[Table]
public class MyApp
{
private EntityRef<ApplicationUser> _applicationUserRef;
[Column(IsPrimaryKey = true, UpdateCheck = UpdateCheck.Never)]
public string AppCode { get; set; }
[Column(UpdateCheck = UpdateCheck.Never)]
public string ProcCode { get; set; }
[Column]
public string ApplicationUserId { get; set; }
[Association(Name = "FK_MyApp_ApplicationUser", Storage = "_applicationUserRef", ThisKey = "ApplicationUserId", OtherKey = "UserId")]
public ApplicationUser ApplicationUserReference
{
get { return _applicationUserRef.Entity; }
set { _applicationUserRef.Entity = value; }
}
}