2012-09-10 15 views
1

所以我想早些時候做一個自定義的映射器,但我得到的建議是很難的(因爲我得到refrences等,我同意這^^),並且我會有更多的運氣與automapper,因爲它很容易等所以我開始爲我想要轉換的類創建映射(我想讓這個應用程序在每週的基礎上從SQLite文件更新一個SQLserver數據庫,表名和屬性是相同的,只有大寫字母不一樣但automapper不區分大小寫那麼大)自動映射從EF(到EF)不可能?

這裏是代碼我想:

Mapper.CreateMap<person, Person>(); 
Mapper.CreateMap<personAbility, PersonAbility>(); 
Mapper.AssertConfigurationIsValid(); 

然後我得到這個人沒有按知道如何將personabilities轉換錯誤propertie。所以,我用Google搜索,並發現我需要包括它:

Mapper.CreateMap<person, Person>() 
.Include<personAbility, PersonAbility>() 
Mapper.CreateMap<personAbility, PersonAbility>(); 
Mapper.AssertConfigurationIsValid(); 

但是這裏抱怨說,它是不是personability需要,但列表(EntityCollection)。所以,我想:

Mapper.CreateMap<person, Person>() 
.Include<EntityCollection<personAbility>, EntityCollection<PersonAbility>>() 
Mapper.CreateMap<personAbility, PersonAbility>(); 
Mapper.AssertConfigurationIsValid(); 

但是它給出了它不知道類型的錯誤,我用Google搜索一些發現:https://github.com/AutoMapper/AutoMapper/wiki/Lists-and-arrays在支持列表中有ISN噸EntityCollection。意思是我碰到另一面牆(死衚衕)?任何人都知道這個解決方案,如果你有其他的解決方案/方式來映射我的數據庫,任何幫助將不勝感激。

+0

爲什麼你不能使用集合或列表的努力? –

+0

因爲EF(實體框架),我用來映射數據庫,使集合放在EntityCollection中。 – Maximc

+0

EF將集合放入列表中。你可以在映射之前包含代碼嗎?也許你的模型背後的代碼(Person&PersonAbility)? –

回答

0

我finnaly得到它固定。包括我在內的錯誤方式。我只是需要映射集合太

加入這一行固定它:(並刪除包括線)

 Mapper.CreateMap<EntityCollection<personAbility>, EntityCollection<PersonAbility>>(); 

感謝所有

0

我不積極,但您可能需要創建地圖的人之前創建的地圖PersonAbility,因爲測繪人的依賴於能夠映射PersonAbility的

+0

之前嘗試過,但沒有抱歉也沒有工作。 – Maximc