Tôi đã sau nơi objectiveData là: IEnumerable<Objective>
LINQ - đối số loại không thể được suy ra từ việc sử dụng trong một lựa chọn
public IList<Objective> createObjectives()
{
var objectiveData = GetContent.GetType5();
var objectives = objectiveData.Select(o => {
var result = new Objective {
Name = o.Name,
Text = o.Text
};
if (o.Name != null && o.Name.EndsWith("01"))
{
result.ObjectiveDetails.Add
(
new ObjectiveDetail
{
Text = o.Text
}
);
}
});
return objectives.ToList();
}
Tôi nhận được một lỗi trên phù hợp với "chọn" nói:
The type arguments for method 'System.Linq.Enumerable.Select<TSource,TResult>
(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,int,TResult>)'
cannot be inferred from the usage. Try specifying the type arguments explicitly.
đây là lớp Mục tiêu của tôi:
public partial class Objective : AuditableTable
{
public Objective()
{
this.ObjectiveDetails = new List<ObjectiveDetail>();
}
public int ObjectiveId { get; set; }
public string Name { get; set; }
public string Text { get; set; }
public virtual ICollection<ObjectiveDetail> ObjectiveDetails { get; set; }
}
Trả về 'GetContent.GetType5()' là gì? –
@ LasseV.Karlsen Đọc câu hỏi từ trên cùng ... –
OK, vấn đề là lựa chọn của bạn không trả lại bất cứ điều gì. –