我有以下类型的自定义类
[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; }
}
在我的DataContext类中调用CreateDatabase()方法时,出现以下错误:
Unable to determine SQL type for 'System.Collections.Generic.List`1[XCell.Framework.data.MyApp]'
请指导我。
答案 0 :(得分:1)
我发现问题是applicationList
标有Column
属性,但它代表了一种关系。
基本上,您必须使用EntityRef<T>
和EntitySet<T>
类以及Association
属性正确映射这些实体之间的关系。
This article可能会有所帮助。
下面更正的映射(对于一对多关系)的示例:
调整后的ApplicationUser
班级
[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; }
}
}
经过调整的MyApp
班级
[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; }
}
}