現在、次のようなクラスでプロパティを設定しています。
MyClass _Temp = (from x in entities.someTable
select new MyClass {
PropertyONE = x.PropertyONE,
PropertyTWO = x.PropertyTWO
}).FirstOrDefault();
this.PropertyONE = _Temp.PropertyONE;
this.PropertyTWO = _Temp.PropertyTWO;
しかし、クラスの別のインスタンスをプレースホルダーとして作成して、実際のインスタンスを作成するよりも良い方法が必要だと思います-このようなものですか?
this = (from x in entities.someTable
select
PropertyONE = x.PropertyONE,
PropertyTWO = x.PropertyTWO
).FirstOrDefault();
何か案は?
* 編集: 詳細情報 ** これをどのように使用しているか:
MVCコントローラーには次のものがあります:
public ActionResult Index(Guid id)
{
MyClass model = new MyClass(id);
Return View(model);
}
そして、「MyClass」のコンストラクターには、ビューに表示するデータを含むクラス (プロパティ) を「プリロード」する上記のコードがあります。
これがそれをよりよく説明することを願っています。