我试图从ASP核心中的查询字符串查询数据库,我试图从查询字符串传递一个字符串数组,只返回具有特定类别的项目。
这些类别位于一个名为CardTypes的集合中,该集合随后包含一个Category对象,我试图将其与我的字符串数组进行比较。
我遇到的问题是每次执行查询时都会返回错误
System.InvalidOperationException:从范围''引用的'Models.Category'类型的变量't.Category',但未定义
public IQueryable<CardViewModel> GetCardsByName(string name, string[] types)
{
var cards = _context.Cards
.Where(c => c.Name.ToLower().Contains(name.ToLower()))
.Where(c=> c.CardTypes.Any(t => types.Contains(t.Category.Name)))
.Take(10).ProjectTo<CardViewModel>();
return cards;
}
型号: 卡片型号
public class Card : IEntityBase
{
public int Id { get; set; }
public string ImagePath { get; set; }
[StringLength(150)]
public string Name { get; set; }
public Rarity Rarity { get; set; }
[StringLength(1250)]
public string Text { get; set; }
[StringLength(1250)]
public string Flavor { get; set; }
[StringLength(5)]
public string Power { get; set; }
[StringLength(5)]
public string Toughness { get; set; }
public ICollection<CardType> CardTypes { get; set; }
public ICollection<CardSubType> CardSubTypes { get; set; }
public ICollection<CardSuperType> CardSuperTypes { get; set; }
public ICollection<CardColor> Colors { get; set; }
public ICollection<Legality> Legalities { get; set; }
public ICollection<Rulling> Rullings { get; set; }
public string Printings { get; set; }
public Set Set { get; set; }
}
CardType:
public class CardType : IEntityBase
{
public int Id { get; set; }
public Card Card { get; set; }
public Category Category { get; set; }
}
类别:
public class Category : IEntityBase
{
public int Id { get; set; }
[StringLength(64)]
public string Name { get; set; }
}