2014-10-28 121 views
0

自定義對象的名單上有一個自定義類下述類型的錯誤,同時存儲在獨立存儲

[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

只是爲了檢查 - 據我瞭解'ApplicationUser'應該與'MyApp'爲一對多關係,對嗎? – danyloid 2014-10-28 10:20:43

+0

@danyloid是的。一個應用程序用戶可以有多個應用 – 2014-10-28 10:24:23

+0

是否有可能將一個應用程序分配給多個用戶? – danyloid 2014-10-28 10:31:07

回答

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; } 
    } 
} 
+0

更正了'ApplicationUserId'屬性'Column'屬性 – danyloid 2014-10-28 11:11:22