对于类型过滤操作,AddAdoptionDetails'不是有效的元数据类型。类型过滤仅对实体类型和复杂类型有效

时间:2019-05-09 07:56:05

标签: c# asp.net asp.net-mvc entity-framework linq

我收到此错误AddAdoptionDetails'不是用于类型过滤操作的有效元数据类型。类型过滤仅对实体类型和复杂类型有效

我的模型类具有一些属性,我复制了如下所示的模型类。

public class AddAdoptionDetails
{
    [Required]
    [MinLength(3, ErrorMessage = "Please enter at least 3 characters")]
    public string firstName { get; set; }

    [Required]
    public string lastName { get; set; }

    [Required]
    [RegularExpression("^[a-zA-Z0-9_\\.-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$", ErrorMessage = "E-mail is not valid")]
    public string email { get; set; }

    [Compare("email", ErrorMessage = "The email and confirmation email do not match.")]
    public string ConfirmEmail { get; set; }

    [Required]
    [MinLength(4, ErrorMessage = "Please enter at least 3 characters")]
    public string address { get; set; }

    [Required]
    [DataType(DataType.PhoneNumber)]
    [RegularExpression(@"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$", ErrorMessage = "Not a valid phone number")]
    public string phone { get; set; }
    [Range(1, int.MaxValue, ErrorMessage = "Please enter a value bigger than {1}")]
    public int tearm { get; set; }
    [Required]
    public string animals { get; set; }
    [Required]
    public string adoptionDate { get; set; }
    [Required]
    [Range(1, int.MaxValue, ErrorMessage = "Amount value bigger than {1}")]
    public string totalAmount { get; set; }

    public bool isActive { get; set; }

    public List<AnimalAdaptionDetails> animalAdaptionDetails { get; set; }
} 

我的控制器类:

这是我使用过LINQ联接的控制器类,我需要将列表转换为强类型模型视图

List<AddAdoptionDetails> Query = _context.AnimalsAndBirdsAdoptions.Join(_context.UserDetails, animal => animal.DonarDetailsId, usr => usr.Id, (animal, usr) =>
             new
             {
                 firstName = usr.FirstName,
                 lastName = usr.LastName,
                 address = usr.Address,
                 email = usr.Email,

                 AnimalsAndBirdsId = animal.AnimalsAndBirdsId,
                // DonarDetailsId = animal.DonarDetailsId,
                Term = animal.Term,
                 PeriodOfAdoption = animal.PeriodOfAdoption,
                 isActive = animal.isActive
             }).Join(_context.NameOfAnimalsAndBirds, adoption => adoption.AnimalsAndBirdsId, animal => animal.Id, (adoption, animal) =>
                 new
                       {
                           adoption,
                           animal
                       }).GroupBy(x =>
                       new
                       {
                           x.adoption.firstName,
                           x.adoption.lastName,
                           x.adoption.address,
                           x.adoption.email,
                           x.adoption.Term,
                           x.adoption.PeriodOfAdoption,
                           x.adoption.isActive
                       }).
                      Select(g =>
                      new
                      {
                          totalAmount = g.Sum(e => e.animal.Amount),
                          g.Key.firstName,
                          g.Key.lastName,
                          g.Key.address,
                          g.Key.email,
                          g.Key.Term,
                          g.Key.PeriodOfAdoption,
                          g.Key.isActive,

                      }).OfType<AddAdoptionDetails>().ToList(); 

0 个答案:

没有答案