これらの2つのテーブルを結合する際に問題があります。c#linqこの結合はどのように実行できますか?
私は私が持っているロジックは次のようになり、私はSurveySectionIdに基づいて2つのテーブルを結合したいLINQの拡張メソッドを使用して、これらの2つのテーブル
SurveySectionTable
-SurveySectionId-(pk)
-surveyId
-SurveySectionName
-comments
-score
...
SurveySectionLoalocazationTable
-SurveySectionLocalizationId-(pk)
-SurveySectionId-(fk)
-SurveySectionName
-comments
...
を持っており、この
NewResult
-SurveySectionId
-surveyId(from SurveySectionTable)
-SurveySectionName (from SurveySectionLocalizationTable)
-comments(from SurveySectionLocalizationTable)
-score (from SurveySectionTable)
...
のような結果を得ますこれを行うにはよりよい方法がありますか?
public async Task<SurveySectionEditViewModel> GetSurveySectionEditLocalizationVm(Guid surveySectionId, Guid localizationId)
{
var defaultTable = await UOF.SurveySectionService.GetById(surveySectionId);
var localizationTable = //get by both parameters;
var result = new SurveySectionEditViewModel
{
SurveySectionId = surveySectionId,
SurveyId = defaultTable.SurveyId,
SurveySectionName = localizationTable.SurveySectionName,
Comments = localizatoinTable.Comments,
Score = defaultTable.Score
};
return result;
}
何か試しましたか?あなたのエンティティクラスはどのように見えますか?エンティティクラスのナビゲーションプロパティとしてテーブル間の関係をモデル化しましたか? –
[LINQのLEFT JOINとエンティティとの重複の可能性がありますか?](0120-18751) –