2011-05-13 74 views
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如此复杂。整个代码首先是要能够创建一个你认为合适的模型?

编辑

所以会出现没有数据库现有的,我们得到的第一个错误(即第一次试运行),因此第二个错误是推测无关。

回答

0

原来,这是一个与此特定关系无关的随机错误。

我将连接从SQL Server CE更改为SQL Server 2008,并给出了一个更有用的错误消息。这次它告诉我哪个列ID是在哪个表上。如果你正在使用SQL Server CE,尝试其更大的兄弟,你可能会有更多的运气。