2014-02-15 56 views
2
_quatationRepository = new QuatationRepository(); 
IList<Quatation> quatationObj = _quatationRepository.GetAll(quatation => quatation.IsDeleted == 0); 
IList<QuatationModel> quatationModelObj = new List<QuatationModel>(); 

AutoMapper.Mapper.CreateMap<Quatation, QuatationModel>(); 
quatationModelObj = AutoMapper.Mapper.Map(quatationObj, quatationModelObj); 
return quatationModelObj; 

public partial class Quatation 
{ 
    public int QuatationId { get; set; } 
    public int FirmId { get; set; } 
    public int ItemId { get; set; } 
    public double Quantity { get; set; } 
    public decimal Price { get; set; } 
    public Nullable Dated { get; set; } 
    public Nullable IsDeleted { get; set; } 
    public Nullable CreatedDate { get; set; } 
    public Nullable CreatedBy { get; set; } 
    public Nullable ModifyDate { get; set; } 
    public Nullable ModifyBy { get; set; } 

    public virtual Firm Firm { get; set; } 
    public virtual Item Item { get; set; } 
} 

public class QuatationModel 
{ 
    public int QuatationId { get; set; } 
    public int? FirmId { get; set; } 
    public int ItemId { get; set; } 
    public double Quantity { get; set; } 
    public decimal Price { get; set; } 
    public DateTime? Dated { get; set; } 
    public int IsDeleted { get; set; } 
    public DateTime? CreatedDate { get; set; } 
    public int? CreatedBy { get; set; } 
    public DateTime? ModifyDate { get; set; } 
    public int? ModifyBy { get; set; } 

    //public string ItemName { get; set; } 
    //public List<SelectListItem> LstFirm { get; set; } 


    public virtual FirmModel Firm { get; set; } 
    public virtual ItemModel Item { get; set; } 
    //public IList<QuatationModel> LstQuatation { get; set; } 
} 
+1

我們可以看到您的Quatation和QuatationModel類屬性嗎? – Seany84

+0

您能否請檢查並儘快給我答覆..其緊急感謝 –

+0

我已更新我的答案。你可以試試看,讓我知道它是否工作? – Seany84

回答

2

沒有處理你必須確保具有相同名稱的屬性具有相同的類型。例如一邊是int而另一邊是Nullable將不起作用(IsDeleted)。

+0

對不起,但它仍然給我同樣的錯誤 –

+0

您需要修復類型所有屬性(那些在兩個類中都有相同名稱的屬性)在兩個類中都匹配,而不僅僅是我給出的示例。如果您已經修復了這些類型,請發佈新課程 – JTMon

0

你能在Quatation類更改爲空的屬性來:

public partial class Quatation 
{ 
    public int QuatationId { get; set; } 
    public int FirmId { get; set; } 
    public int ItemId { get; set; } 
    public double Quantity { get; set; } 
    public decimal Price { get; set; } 
    public DateTime? Dated { get; set; } 
    public int IsDeleted { get; set; } 
    public DateTime? CreatedDate { get; set; } 
    public int? CreatedBy { get; set; } 
    public DateTime? ModifyDate { get; set; } 
    public int? ModifyBy { get; set; } 

    public virtual Firm Firm { get; set; } 
    public virtual Item Item { get; set; } 
} 

,然後嘗試映射即

_quatationRepository = new QuatationRepository(); 
IList<Quatation> quatationObj = _quatationRepository.GetAll(quatation => quatation.IsDeleted == 0); 
IList<QuatationModel> quatationModelObj = new List<QuatationModel>(); 

AutoMapper.Mapper.CreateMap<IList<Quatation>, IList<QuatationModel>>(); 
quatationModelObj = AutoMapper.Mapper.Map<IList<Quatation>, IList<QuatationModel>>(quatationObj.ToList()); 
return quatationModelObj; 
0

對不起,我遲到答覆 實際發生的錯誤是由於我與另一個的關係表。 我只是刪除刪除外鍵和更新我的edmx文件。 然後錯誤得到解決。

由於所有相關表中的數據不一致。

再次感謝您的回覆。

相關問題