我有一个DataContract
类,我正在尝试转换为另一个类,Movie
但是对于该属性Movie.Characters
,我收到了错误...
无法将源类型“
void
”转换为目标类型“ICollection<Character>
”
我怎样才能创建一个新Movie
的Character
属性设置正确映射到每个Person
和Movie
?
var movies = dataContract.Movies.Select(m => new Movie {
Id = m.Id,
Title = m.Title,
Characters = m.AbridgedCast.ToList().ForEach(p => new Person { Name = p.Name,
RottenTomatoesId = p.Id,
Characters = p.Characters.ToList().ForEach(c => new Character { Name = c })})
});
MoviesDataContract.cs
public class MoviesDataContract {
[DataMember(Name = "total")]
public int Total { get; set; }
[DataMember(Name = "movies")]
public IEnumerable<Movie> Movies { get; set; }
#region Internal Classes
[DataContract]
public class Movie {
[DataMember(Name = "id")]
public int Id { get; set; }
[DataMember(Name = "title")]
public string Title { get; set; }
[DataMember(Name = "abridged_cast")]
public virtual IEnumerable<Person> AbridgedCast { get; set; }
}
[DataContract]
public class Person {
[DataMember(Name = "name")]
public string Name { get; set; }
[DataMember(Name = "id")]
public int Id { get; set; }
[DataMember(Name = "characters")]
public IEnumerable<string> Characters { get; set; }
}
#endregion
}
电影.cs
public partial class Movie {
public Movie() {
this.Characters = new HashSet<Character>();
}
public int Id { get; set; }
public string Title { get; set; }
public virtual ICollection<Character> Characters { get; set; }
}
public partial class Character {
public System.Guid Id { get; set; }
public int MovieId { get; set; }
public System.Guid PersonId { get; set; }
public string Name { get; set; }
public virtual Movie Movie { get; set; }
public virtual Person Person { get; set; }
}
public partial class Person {
public Person() {
this.Characters = new HashSet<Character>();
}
public System.Guid Id { get; set; }
public string Name { get; set; }
public int RottenTomatoesId { get; set; }
public virtual ICollection<Character> Characters { get; set; }
}