Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server Odata>EF>从表中选择SQL_Sql Server_Entity Framework_Odata - Fatal编程技术网

Sql server Odata>EF>从表中选择SQL

Sql server Odata>EF>从表中选择SQL,sql-server,entity-framework,odata,Sql Server,Entity Framework,Odata,我的POCO表定义如下,因为我希望最终将其用作Dynamics CE上的虚拟实体,所以它应该能够在以下集合的OData端点上使用$expand public partial class ak_iglead_V { [Key] public Guid ak_igLeadId_V { get; set; } //the pk .... public virtual ICollection<ak_Match> ak_MatchLead { get; s

我的POCO表定义如下,因为我希望最终将其用作Dynamics CE上的虚拟实体,所以它应该能够在以下集合的OData端点上使用$expand

public partial class ak_iglead_V
{

    [Key]
    public Guid ak_igLeadId_V { get; set; }  //the pk
     ....
    public virtual ICollection<ak_Match> ak_MatchLead { get; set; }

}

public partial class ak_Match
{
    [Key]
    [Column(Order = 0)]
    public Guid MatchId { get; set; }
    public Guid ak_LeadId { get; set; } //Foreign key to 
    public Guid? ak_matchLeadId { get; set; } //forreign key to 
    public Guid? ak_matchContactId { get; set; }
    public decimal? ak_Confidance { get; set; }
    public string ak_Name { get; set; }
    [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly"),ForeignKey("ak_LeadId")]
    public virtual ak_iglead_V ak_iglead_V { get; set; }
    [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly"),ForeignKey("ak_matchLeadId")]
    public virtual ak_iglead_V ak_iglead_V_matched { get; set; }
}
这是代码片段:

`public List<ak_Match> Matches { get; set; }
 public void Initialize()
{
    var matches = from m in db.akMatches
                  select m;
    this.Matches= matches.ToList() ;
`
并生成异常,因为它找不到应该是集合的列

它能不能在SQL中以某种方式被忽略? 不知怎的,因为这是同一张桌子的钥匙,我想它不知怎么搞糊涂了

System.Data.Entity.Core.EntityCommandExecutionException: 执行命令定义时出错。有关详细信息,请参见内部异常

SqlException:

列名称“ak_iglead_V_ak_igLeadId_V”无效 列名“AKU IGLEADU V_AKU igLeadId_Vmatched”无效


导航属性和外键属性之间的关系不符合EF的约定,因此需要显式配置关系。例如,使用。

AKU匹配表应处理同一AKU igLead v实体的外键: 请注意指向命名的nvigation属性的[ForeignKey]属性

public partial class ak_Match //V_CE_ak_match
{
    [Key]
    public Guid ak_MatchId { get; set; }

    [ForeignKey("FK_ak_Match_ak_igLead_V")]
    public Guid ak_LeadId { get; set; }

    [ForeignKey("FK_ak_Match_ak_igLead_Matched")]
    public Guid? ak_matchLeadId { get; set; }
    public Guid? ak_matchContactId { get; set; }
    public decimal? ak_Confidance { get; set; }
    public string ak_Name { get; set; }

    [InverseProperty("ak_MatchLead")]
    public virtual ak_iglead_V FK_ak_Match_ak_igLead_V { get; set; }

    [InverseProperty("ak_MatchedLead")]
    public virtual ak_iglead_V FK_ak_Match_ak_igLead_Matched { get; set; }
}

@david-这为我指明了正确的方向。

你能提供DDL表吗?它有外键吗?我添加了带有PK的“ak_iglead_V”表,两个字段“ak_LeadId”和“ak_matchLeadId”是该表的外键。
public partial class ak_Match //V_CE_ak_match
{
    [Key]
    public Guid ak_MatchId { get; set; }

    [ForeignKey("FK_ak_Match_ak_igLead_V")]
    public Guid ak_LeadId { get; set; }

    [ForeignKey("FK_ak_Match_ak_igLead_Matched")]
    public Guid? ak_matchLeadId { get; set; }
    public Guid? ak_matchContactId { get; set; }
    public decimal? ak_Confidance { get; set; }
    public string ak_Name { get; set; }

    [InverseProperty("ak_MatchLead")]
    public virtual ak_iglead_V FK_ak_Match_ak_igLead_V { get; set; }

    [InverseProperty("ak_MatchedLead")]
    public virtual ak_iglead_V FK_ak_Match_ak_igLead_Matched { get; set; }
}