[英]Entity Framework 6 and navigational property issue
Im hoping to get your help here. 我希望在这里得到您的帮助。 Im very new to EF and am having some troubles.
我对EF非常陌生,遇到了一些麻烦。 I am using the Database First approach and have a database in Azure that I have to retreive data from.
我正在使用数据库优先方法,并且在Azure中有一个数据库,必须从中检索数据。
[DataContract]
[Table("A")]
public class AgencyDC
{
[DataMember]
[Key]
public string AID { get; set; }
public string AName { get; set; }
public string GeneralEmailAddress { get; set; }
public string WebsiteURL { get; set; }
[DataMember]
[ForeignKey("AID")]
[IgnoreDataMember]
public virtual AExtensionDC AExtension { get; set; }
}
[DataContract]
[Table("AExtension")]
public class AExtensionDC
{
[DataMember]
[Key]
public string AID { get; set; }
[DataMember]
public bool? IsActive { get; set; }
public bool? IsOptedOut { get; set; }
public DateTime? LastUpdated { get; set; }
}
I am trying to use EF6 to retreive my records using DBSets in my context.. 我正在尝试使用EF6在上下文中使用DBSet检索记录。
public List<ADataCcontract> GetAllAs()
{
using (AContext _aCtx = new AContext())
{
var mylist = _aCtx.A.Include("AExtension").ToList();
return mylist;
}
}
Now, I should be getting back 547 records back with only 1 of them having the AExtension navigational property having content within. 现在,我应该找回547条记录,其中只有1条具有AExtension导航属性,其中包含内容。 The other 546 records should contain NULL.
其他546条记录应包含NULL。 However, for some reason, I am only getting what appears to be a record that has a match in both tables.
但是,由于某种原因,我只能得到似乎在两个表中都匹配的记录。 In SQL speak, I kind of just want a left join so that I return ALL rows from AE entity and OPTIONALLY matches in AE.
用SQL来说,我只是想要一个左联接,以便我从AE实体返回所有行,并在AE中返回OPTIONALLY匹配项。
I hope this makes sense. 我希望这是有道理的。
If possible, if you have a fix, could you please post an example I could referent? 如果可能的话,如果您有修复程序,请提供一个我可以参考的示例吗? I am really stuck.
我真的被困住了。
I think this SO Answer might get you most of the way? 我认为这个SO Answer可能会让您受益匪浅? https://stackoverflow.com/a/4299667/78551
https://stackoverflow.com/a/4299667/78551
Basically Include does a left outer join or left join as 'outer' is actually optional in SQL. 基本上,Include包含左外部联接或左联接,因为“外部”实际上在SQL中是可选的。
A left join / inner join will be performed by ´.Include´ if your fields have/lack of nullability. 如果您的字段具有可空性,则左连接/内部连接将由“ .include”执行。
To review your query put a breakpoint and check this value: 要查看您的查询,请设置一个断点并检查此值:
var myQuery = _aCtx.A.Include("AExtension").ToTraceString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.