Bire ben şu iki modelVarlık Framework Kod İlk olan İlişki
public class Account
{
public int Id { get; set; }
public string Name { get; set; }
public int CurrentPeriodId { get; set; }
[ForeignKey("CurrentPeriodId")]
public virtual Period CurrentPeriod { get; set; }
public virtual ICollection<Period> Periods { get; set; }
}
public class Period
{
public int Id { get; set; }
public int AccountId { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public virtual Account Account { get; set; }
}
Ve aşağıdaki sorguyu çalıştırmak çalışıyorum:
from p in context.Periods
where p.AccountId == accountId &&
p.Id == p.Account.CurrentPeriodId
select p.StartDate
Ve Geçersiz" diyerek bir sql istisna olsun sütun adı Account_AccountId ".
ben Hesap taraftan bu yaklaşım biliyorum ve
from a in context.Accounts
where a.Id == id
select a.CurrentPeriod.StartDate
böyle bir şey yapmak Ama ilişki diğer sorgu işe almak için nasıl ayarlanacağını bilmek istiyorum. Neyi kaçırıyorum?
(başlıkla parçası "Bir Sıfır biri veya bir İlişki Harita"). –
@Nick Olsen: Cevabımı güncelledi. – Kamyar