VS2010を使用しているWebアプリケーションプロジェクトでORMとしてLINQを使用しています。 SQLデータベースにERを定義し、ORMにデータベーステーブルをドラッグアンドドロップしました。転送テーブルには、4つの異なる列を持つ病院テーブルとの4つの関係があります。列の1つがFK、int、nullではありません。他の3つはFK、int、nullです。 DBMLでは、TransferクラスにはHospitalクラスへの4つの関連があります。必要なTransfer.Hospital(FK、int、not null)との関連付けには、次のプロパティがあります。ASP.Net MVC2のアソシエーション
Cardinality: OneToMany
Child Property: True
Access: Public
Inheritance Modifier: (None)
Name = Transfers1
Parent Property
Access: Public
Inheritance Modifier: (None)
Name: HospitalSrcOrDest
Participating Properties: Hospital.HospitalID -> Transfer.Hospital
Unique: False
ビューページで使用されるビューモデルには、転送タイプの転送プロパティがあります。 Model.Transfer.Hospitalは常に整数値を持ちます。ただし、次のページスクリプトのModel.Transfer.HospitalSrcOrDestは常にnullです。 HospitalNameはHospital_Transfer1の関連付けによって自動的に取得されませんか?ありがとう。
<%: Model.Transfer.HospitalSrcOrDest != null ? Model.Transfer.HospitalSrcOrDest.HospitalName : string.Empty%>
loadoptionをリポジトリコンストラクタに提案どおりに設定しましたが、違いはありません。 // DataLoadOptionsを作成します。 DataLoadOptions dlo = new DataLoadOptions(); //投稿を取得したときに必ずタグを取得します。 dlo.LoadWith(p => p.Tags); //これらのオプションをDataContextに設定します。 db.LoadOptions = dlo; –
user266909