1
爲什麼這映射(在SQL CE 4.0)EF代碼第一個模式生成問題
ToTable("USERS");
HasKey(c => c.Id);
Property(c => c.Id).HasColumnName("USERS_ID");
Property(c => c.ActiveDirectoryUsername).HasColumnName("AD_ID");
Property(c => c.LastUpdated).HasColumnName("LastUpdated").IsOptional();
Property(c => c.Active).HasColumnName("Active").IsOptional();
Property(c => c.AccountType).HasColumnName("AccountType").IsOptional();
HasOptional(c => c.Contact).WithMany().Map(c => c.MapKey("CONTACT_ID"));
Map<UserCompanyLink>(m => m.Requires("IsCompanyDelegate").HasValue(1));
Map<UserDirectorLink>(m => m.Requires("IsCompanyDelegate").HasValue(0));
產生這個錯誤
SetUp : System.InvalidOperationException : The database creation succeeded, but the creation of the database objects did not. See inner exception for more details.
----> System.Data.SqlServerCe.SqlCeException : A column ID occurred more than once in the specification.
我希望能夠看到的模式SQL生成到調試這個...
編輯
有加入IsCompanyDelegate到UserLink基礎機構,我現在得到
SetUp : System.Data.DataException : An exception occurred while initializing the database. See the InnerException for details.
----> System.Data.EntityCommandCompilationException : An error occurred while preparing the command definition. See the inner exception for details.
----> System.Data.MappingException :
(69,10) : error 3023: Problem in mapping fragments starting at lines 69, 79, 88, 172:Column UserLink.IsCompanyDelegate has no default value and is not nullable. A column value is required to store entity data.
An Entity with Key (PK) will not round-trip when:
((PK is NOT in 'UserLinks' EntitySet OR Entity is type [eServices.Admin.Data.Contexts.UserLink]) AND (PK is in 'UserLinks' EntitySet OR PK plays Role 'UserLink_Contact_Source' in AssociationSet 'UserLink_Contact'))
奮鬥和神祕的天書。
爲什麼映射TPH如此複雜。整個代碼首先是要能夠創建一個你認爲合適的模型?
編輯
所以會出現沒有數據庫現有的,我們得到的第一個錯誤(即第一次試運行),因此第二個錯誤是推測無關。