我目前正在开发一个搜索页面。我需要返回一个只包含所有主题标签ID存储在int[] ST中的主题详情列表。目前,此行代码(ST == null ? true : ST.Contains(b.ThemeTagID))似乎给我一个错误。
额外信息:无法创建类型为“System.Int32[]”的空常量值。在此上下文中仅支持实体类型、枚举类型或基元类型。
额外信息:无法创建类型为“System.Int32[]”的空常量值。在此上下文中仅支持实体类型、枚举类型或基元类型。
public ActionResult Index(int ProviderID = 0, string Description = null, int[] ST = null)
{
var themedetail = from t in db.ThemeDetail
from b in t.ThemeTags
where (
(string.IsNullOrEmpty(Description) ? true : t.Description.ToLower().Contains(Description.ToLower())) &&
(ProviderID == 0 ? true : t.ProviderID == ProviderID) &&
(ST == null ? true : ST.Contains(b.ThemeTagID))
)
select t;
ViewBag.ProviderID = new SelectList(db.ProviderDetails, "ProviderID", "ProviderName");
ViewBag.MultiselectFeatures = new MultiSelectList(db.ThemeFeatures, "ThemeFeatureID", "ThemeFeaturesName");
ViewBag.MultiselectTags = new MultiSelectList(db.ThemeTags, "ThemeTagID", "TagName");
return View(themedetail.ToList());
}
The Models are...
[Table("ThemeDetail")]
public class ThemeDetail : Entity
{
[Required]
[Display(Name = "Name")]
public string ThemeName { get; set; }
public ThemeDetail()
{
ThemeFeatures = new List<ThemeFeature>();
ThemeTags = new List<ThemeTag>();
ThemeImages = new List<ThemeImage>();
}
public virtual ICollection<ThemeFeature> ThemeFeatures { get; set; }
public virtual ICollection<ThemeTag> ThemeTags { get; set; }
public virtual ICollection<ThemeImage> ThemeImages { get; set; }
}
[Table("ThemeTags")]
public class ThemeTag
{
[Key]
[Display(Name = "Theme Tag ID")]
public int ThemeTagID { get; set; }
[Display(Name = "Tag Name")]
[Required]
public string TagName { get; set; }
public virtual ICollection<ThemeDetail> ThemeDetail { get; set; }
}