繁体   English   中英

ThisKey列的数量与OtherKey列的数量不同

[英]The number of ThisKey columns is different from the number of OtherKey columns

我正在开发Windows Phone应用程序,而LINQ遇到了麻烦。 当我尝试运行我的应用程序时,它显示以下消息:

System.Data.Linq.dll中发生了类型为'System.InvalidOperationException'的未处理异常

附加信息:ThisKey列的数量与类型为“ Pessoa”的关联属性“ Coletor”的OtherKey列的数量不同。

我已经尝试过在google上找到的所有内容,但没有成功。 有问题的文件如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq.Mapping;
using System.Data.Linq;

namespace Aplicativo_Windows_Phone
{
    #pragma warning disable 0169, 0649
    [Table(Name="Pessoas")]
    public class Pessoa
    {
        [Column(IsDbGenerated = true, IsPrimaryKey = true)]
        public int Id { get; set; }

        [Column]
        public string Nome { get; set; }

        [Column]
        public string Email { get; set; }

        [Column]
        public string Senha { get; set; }

        [Column]
        public string Profissao { get; set; }

        [Column]
        public int Idade { get; set; }

        [Column]
        public string Endereco { get; set; }

        [Column]
        public string Cidade { get; set; }

        [Column]
        public string Estado { get; set; }

        [Column(IsPrimaryKey = true, Name = "Coletor")]
        private int? coletorId;

        private EntityRef<Coletor> _coletor = new EntityRef<Coletor>();

        [Association(Name = "FK_Pessoas_PessoaColetores", IsForeignKey = true, Storage = "_coletor", ThisKey = "coletorId")]
        public Coletor Coletor
        {
            get { return _coletor.Entity; }
            set { _coletor.Entity = value; }
        }

        private EntitySet<PessoaColetor> _pessoaColetores = new EntitySet<PessoaColetor>();

        [Association(Name = "FK_PessoaColetores_Pessoa", Storage = "_pessoaColetores", OtherKey = "pessoaId", ThisKey = "Id")]
        private ICollection<PessoaColetor> PessoaColetores
        {
            get { return _pessoaColetores; }
            set { _pessoaColetores.Assign(value); }
        }

        public ICollection<Coletor> Coletores
        {
            get { return (from pc in PessoaColetores select pc.Coletor).ToList(); }
        }


    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq.Mapping;
using System.Data.Linq;
using Microsoft.Phone.Data.Linq;
using Microsoft.Phone.Data.Linq.Mapping;

namespace Aplicativo_Windows_Phone
{
#pragma warning disable 0169, 0649
    [Table(Name="Coletores")]
    public class Coletor
    {
        [Column(IsPrimaryKey = true, IsDbGenerated = true)]
        public int Id { get; set; }

        [Column]
        public float Latitude { get; set; }

        [Column]
        public float Longitude { get; set; }

        [Column]
        public string Nome { get; set; }

        private EntitySet<PessoaColetor> _pessoaColetores = new EntitySet<PessoaColetor>();
        [Association(Name = "FK_PessoaColetores_Coletor", Storage = "_pessoaColetores", ThisKey = "Id", OtherKey = "coletorId")]
        private ICollection<PessoaColetor> PessoaColetores
        {
            get { return _pessoaColetores; }
            set { _pessoaColetores.Assign(value); }
        }



        [Column(IsPrimaryKey = true, Name = "Ocorrencias")]
        private int? ocorrenciaId;

        private EntityRef<Ocorrencia> _ocorrencia = new EntityRef<Ocorrencia>();

        [Association(Name = "FK_Coletores_ColetorOcorrencias", IsForeignKey = true, Storage = "_ocorrencia", ThisKey = "ocorrenciaId")]
        public Ocorrencia Ocorrencia
        {
            get { return _ocorrencia.Entity; }
            set { _ocorrencia.Entity = value; }
        }

        private EntitySet<ColetorOcorrencia> _coletorOcorrencias = new EntitySet<ColetorOcorrencia>();

        [Association(Name = "FK_ColetorOcorrencias_Coletor", Storage = "_coletorOcorrencias",ThisKey = "Id", OtherKey = "coletorId")]
        private ICollection<ColetorOcorrencia> ColetorOcorrencias
        {
            get { return _coletorOcorrencias; }
            set { _coletorOcorrencias.Assign(value); }
        }

        public ICollection<Pessoa> Pessoas
        {
            get { return (from pc in PessoaColetores select pc.Pessoa).ToList(); }
        }

        public ICollection<Ocorrencia> Ocorrencias
        {
            get { return (from co in ColetorOcorrencias select co.Ocorrencia).ToList(); }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq.Mapping;
using System.Data.Linq;
using Microsoft.Phone.Data.Linq;
using Microsoft.Phone.Data.Linq.Mapping;

namespace Aplicativo_Windows_Phone
{
#pragma warning disable 0169, 0649
    [Table(Name = "PessoaColetores")]
    class PessoaColetor
    {
        [Column(IsPrimaryKey = true, Name = "Coletor")]
        private int coletorId;
        private EntityRef<Coletor> _coletor = new EntityRef<Coletor>();
        [Association(Name = "FK_PessoaColetores_Coletores", IsForeignKey = true, Storage = "_coletor", ThisKey = "coletorId")]
        public Coletor Coletor
        {
            get { return _coletor.Entity; }
            set { _coletor.Entity = value; }
        }

        [Column(IsPrimaryKey = true, Name = "Pessoa")]
        private int pessoaId;
        private EntityRef<Pessoa> _pessoa = new EntityRef<Pessoa>();
        [Association(Name = "FK_PessoaColetores_Pessoas", IsForeignKey = true, Storage = "_pessoa", ThisKey = "pessoaId")]
        public Pessoa Pessoa
        {
            get { return _pessoa.Entity; }
            set { _pessoa.Entity = value; }
        }
    }
}

这个主键不应该

[Column(IsPrimaryKey = true, Name = "Coletor")]
    private int? coletorId;

是外键

[Column(IsForeignKey= true, Name = "Coletor")]
    private int? coletorId;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM