var range = this.dataStore.Query<NotificationConfiguration>()
.Range(p => new NotificationConfigurationViewModel(p, from x in p.Events where !(x.Code == null || x.Code.Equals("")) select x.Code), pageNumber);
return this.View(range);
IEnumerable を返したい上記のコードがありますが、「サブクエリが複数の値を返しました。これは、サブクエリが =、!=、<、<=、>、>= に続く場合、またはサブクエリがコードが実行されるたびに、式として使用されます。クエリが 1 つの値だけを返したいことは理解していますが、意図したとおりに値のセットを返すにはどうすればよいですか? 助けてください!
少し明確にさせてください...範囲に新しいオブジェクトを含めたいです。データベースを通過するクエリがあります。次のビューモデルコンストラクターを使用して変換するデータを返します。
public NotificationConfigurationViewModel(NotificationConfiguration notification , IEnumerable<string> codes)
{
Contract.Requires(notification != null);
this.notification = notification;
this.codes = codes;
}
各通知構成にはプロパティがあり、それに関連付けられたイベントのリストがあります。上記のリストのコードだけが必要です。
もう一度明確にするだけです。クエリで NotificationConfiguration と IEnumerable (後で SB を使用して単一の文字列に変換します) を返してもらいたいです。クエリによってこれら 2 つの項目が返されたら、ビュー モデルのコンストラクターを使用して変換し、DataTable を使用してすべてのデータを適切に表示できるようにします。私が探している答えはおそらく非常に具体的ですが、IEnumerableを返したいときにサブクエリエラーが発生する理由とその修正方法を理解する必要があります。また、注意してください... .netドキュメントによると、コードはIEnumerableを返す必要がありますが、何らかの理由でまだクラッシュしています。関連するコード サンプルをもう一度示します。
[HttpPost]
public ActionResult Index(DataTableRequest requestedData)
{
using (this.dataStore.Session.BeginTransaction())
{
return this.dataStore.Query<NotificationConfiguration>()
.TableRange(requestedData, p => new NotificationConfigurationViewModel(p, from x in p.Events select x.Code));
}
}
.
public NotificationConfigurationViewModel(NotificationConfiguration notification , IEnumerable<string> events)
{
Contract.Requires(notification != null);
this.notification = notification;
this.events = events;
}
.
[Display(Name = "Events")]
public virtual string EventTypeCodes
{
get
{
var codes = new StringBuilder();
foreach (var item in this.events)
{
codes.Append(item + ",");
}
return codes.ToString().TrimEnd(',');
}
}