【发布时间】:2013-12-16 18:59:02
【问题描述】:
有人能解释一下这个错误是什么意思吗?我以前用过一次自动映射器,但从来没有出现过这种错误。
错误
服务器在处理请求时遇到错误。异常消息是“缺少类型映射配置或不支持的映射。映射类型:Char -> QuestionDto System.Char -> CollectiveDistributedPolling.QuestionDto 目标路径:QuestionDto.Question1.Question1.Question10[0] 源值:R'。
Service1.svc.cs
public Service1() {
Mapper.CreateMap<Question, QuestionDto>();
Mapper.CreateMap<QuestionDto, Question>();
}
private Question MapToQuestion(QuestionDto q)
{
return Mapper.Map<QuestionDto, Question>(q);
}
private QuestionDto MapToQuestionDto(Question q) <<< EXCEPTION GETS THROWN HERE
{
return Mapper.Map<Question, QuestionDto>(q);
}
public QuestionDto ThrowQuestion(string user)
{
return MapToQuestionDto(Database.GetInstance().ThrowQuestion(user));
}
IService1.cs
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
QuestionDto ThrowQuestion(String user);
[DataContract]
public class QuestionDto
{
[DataMember]
public int ID { get; set; }
[DataMember]
public int next { get; set; }
[DataMember]
public String question { get; set; }
[DataMember]
public ICollection<QuestionDto> QuestionPhrase { get; set; }
[DataMember]
public QuestionDto Next{ get; set; }
[DataMember]
public ICollection<QuestionAnswerDto> QuestionAnswer { get; set; }
[DataMember]
public ICollection<UserAnswerDto> UserAnswer { get; set; }
}
Question.cs
public partial class Question
{
public Question()
{
this.QuestionPhrase = new HashSet<Question>();
this.QuestionAnswer = new HashSet<QuestionAnswer>();
this.UserAnswer = new HashSet<UserAnswer>();
}
public int ID { get; set; }
public string question { get; set; }
public Nullable<int> next { get; set; }
public virtual ICollection<Question> QuestionPhrase { get; set; }
public virtual Question Next { get; set; }
public virtual ICollection<QuestionAnswer> QuestionAnswer { get; set; }
public virtual ICollection<UserAnswer> UserAnswer { get; set; }
}
}
感谢 danludwig,我可以查明问题所在。有关系
[DataMember]
public QuestionDto Next{ get; set; }
但我觉得这个映射很好
【问题讨论】:
-
请发布您的
Question课程。char类型的任一对象是否有任何属性? -
@danludwig 发布了 Question 类,但里面没有 char 类型
-
你可以用 Mapper.DynamicMap 代替。
标签: c# json wcf linq-to-sql automapper