1

你好,美好的一天 

我希望你能帮助我,然后我解释我的问题:

这些是我的实体:

http://i.stack.imgur.com/OjZmX.jpg

我需要使用 POCO 创建这样的关系,例如带有 SDN 的 resultadobusquedaofac,为此我使用 POCO 模板

http://i.stack.imgur.com/qYbzy.jpg

那么我自己相信这些实体内部的伙伴关系:

ResultadoBusquedaOfac

public partial class ResultadoBusquedaOfac
{
    #region Primitive Properties

    public virtual int ent_num
    {
        get;
        set;
    }

    public virtual string SDN_Name
    {
        get;
        set;
    }

    public virtual int KeyCliente
    {
        get;
        set;
    }

    public virtual string HayCoincidencia
    {
        get;
        set;
    }

    public virtual string HayCoincidenciaAlias
    {
        get;
        set;
    }

    #endregion

    public virtual ICollection<OFAC_SDN> OFAC_SDN
    {
        get
        {
            if (_oFAC_SDN == null)
            {
                var newCollection = new FixupCollection<OFAC_SDN>();
                newCollection.CollectionChanged += FixupOFAC_SDN;
                _oFAC_SDN = newCollection;
            }
            return _oFAC_SDN;
        }
        set
        {
            if (!ReferenceEquals(_oFAC_SDN, value))
            {
                var previousValue = _oFAC_SDN as FixupCollection<OFAC_SDN>;
                if (previousValue != null)
                {
                    previousValue.CollectionChanged -= FixupOFAC_SDN;
                }
                _oFAC_SDN = value;
                var newValue = value as FixupCollection<OFAC_SDN>;
                if (newValue != null)
                {
                    newValue.CollectionChanged += FixupOFAC_SDN;
                }
            }
        }
    }
    private ICollection&lt;OFAC_SDN&gt; _oFAC_SDN;</em></strong>


    private void FixupOFAC_SDN(object sender, NotifyCollectionChangedEventArgs e)
    {
        if (e.NewItems != null)
        {
            foreach (OFAC_SDN item in e.NewItems)
            {
                item.ResultadoBusquedaOfac = this;
            }
        }

        if (e.OldItems != null)
        {
            foreach (OFAC_SDN item in e.OldItems)
            {
                if (ReferenceEquals(item.ResultadoBusquedaOfac, this))
                {
                    item.ResultadoBusquedaOfac = null;
                }
            }
        }
    }
}

}OFAC_SDN

public partial class OFAC_SDN
{
    #region Primitive Properties

   <strong><em> public virtual Nullable&lt;int&gt; id_Ofac
    {
        get { return _id_Ofac; }
        set
        {
            try
            {
                _settingFK = true;
                if (_id_Ofac != value)
                {
                    if (ResultadoBusquedaOfac != null &amp;&amp; ResultadoBusquedaOfac.ent_num != value)
                    {
                        ResultadoBusquedaOfac = null;
                    }
                    _id_Ofac = value;
                }
            }
            finally
            {
                _settingFK = false;
            }
        }
    }
    private Nullable&lt;int&gt; _id_Ofac;</em></strong>

    public virtual int ent_num
    {
        get;
        set;
    }

    public virtual string SDN_Name
    {
        get;
        set;
    }

    public virtual string SDN_Type
    {
        get;
        set;
    }

    public virtual string Program
    {
        get;
        set;
    }

    public virtual string Title
    {
        get;
        set;
    }

    public virtual string Call_Sign
    {
        get;
        set;
    }

    public virtual string Vess_type
    {
        get;
        set;
    }

    public virtual string Tonnage
    {
        get;
        set;
    }

    public virtual string GRT
    {
        get;
        set;
    }

    public virtual string Vess_flag
    {
        get;
        set;
    }

    public virtual string Vess_owner
    {
        get;
        set;
    }

    public virtual string Remarks
    {
        get;
        set;
    }

    #endregion
    #region Navigation Properties

    public virtual ResultadoBusquedaOfac ResultadoBusquedaOfac
    {
        get { return _resultadoBusquedaOfac; }
        set
        {
            if (!ReferenceEquals(_resultadoBusquedaOfac, value))
            {
                var previousValue = _resultadoBusquedaOfac;
                _resultadoBusquedaOfac = value;
                FixupResultadoBusquedaOfac(previousValue);
            }
        }
    }
    private ResultadoBusquedaOfac _resultadoBusquedaOfac;</em></strong>

    public virtual ICollection&lt;OFAC_ADD&gt; OFAC_ADD
    {
        get
        {
            if (_oFAC_ADD == null)
            {
                var newCollection = new FixupCollection&lt;OFAC_ADD&gt;();
                newCollection.CollectionChanged += FixupOFAC_ADD;
                _oFAC_ADD = newCollection;
            }
            return _oFAC_ADD;
        }
        set
        {
            if (!ReferenceEquals(_oFAC_ADD, value))
            {
                var previousValue = _oFAC_ADD as FixupCollection&lt;OFAC_ADD&gt;;
                if (previousValue != null)
                {
                    previousValue.CollectionChanged -= FixupOFAC_ADD;
                }
                _oFAC_ADD = value;
                var newValue = value as FixupCollection&lt;OFAC_ADD&gt;;
                if (newValue != null)
                {
                    newValue.CollectionChanged += FixupOFAC_ADD;
                }
            }
        }
    }
    private ICollection&lt;OFAC_ADD&gt; _oFAC_ADD;

    public virtual ICollection&lt;OFAC_ALT&gt; OFAC_ALT
    {
        get
        {
            if (_oFAC_ALT == null)
            {
                var newCollection = new FixupCollection&lt;OFAC_ALT&gt;();
                newCollection.CollectionChanged += FixupOFAC_ALT;
                _oFAC_ALT = newCollection;
            }
            return _oFAC_ALT;
        }
        set
        {
            if (!ReferenceEquals(_oFAC_ALT, value))
            {
                var previousValue = _oFAC_ALT as FixupCollection&lt;OFAC_ALT&gt;;
                if (previousValue != null)
                {
                    previousValue.CollectionChanged -= FixupOFAC_ALT;
                }
                _oFAC_ALT = value;
                var newValue = value as FixupCollection&lt;OFAC_ALT&gt;;
                if (newValue != null)
                {
                    newValue.CollectionChanged += FixupOFAC_ALT;
                }
            }
        }
    }
    private ICollection&lt;OFAC_ALT&gt; _oFAC_ALT;

    #endregion

    #region Association Fixup

    private bool _settingFK;

    private void FixupResultadoBusquedaOfac(ResultadoBusquedaOfac previousValue)
    {
        if (previousValue != null &amp;&amp; previousValue.OFAC_SDN.Contains(this))
        {
            previousValue.OFAC_SDN.Remove(this);
        }

        if (ResultadoBusquedaOfac != null)
        {
            if (!ResultadoBusquedaOfac.OFAC_SDN.Contains(this))
            {
                ResultadoBusquedaOfac.OFAC_SDN.Add(this);
            }
            if (id_Ofac != ResultadoBusquedaOfac.ent_num)
            {
                id_Ofac = ResultadoBusquedaOfac.ent_num;
            }
        }
        else if (!_settingFK)
        {
            id_Ofac = null;
        }
     }

    private void FixupOFAC_ADD(object sender, NotifyCollectionChangedEventArgs e)
    {
        if (e.NewItems != null)
        {
            foreach (OFAC_ADD item in e.NewItems)
            {
                item.OFAC_SDN = this;
            }
        }

        if (e.OldItems != null)
        {
            foreach (OFAC_ADD item in e.OldItems)
            {
                if (ReferenceEquals(item.OFAC_SDN, this))
                {
                    item.OFAC_SDN = null;
                }
            }
        }
    }

    private void FixupOFAC_ALT(object sender, NotifyCollectionChangedEventArgs e)
    {
        if (e.NewItems != null)
        {
            foreach (OFAC_ALT item in e.NewItems)
            {
                item.OFAC_SDN = this;
            }
        }

        if (e.OldItems != null)
        {
            foreach (OFAC_ALT item in e.OldItems)
            {
                if (ReferenceEquals(item.OFAC_SDN, this))
                {
                    item.OFAC_SDN = null;
                }
            }
        }
    }

    #endregion
}

}

现在当我运行测试查询时:

公共部分类 Form1 : Form { public Form1() { InitializeComponent();

        LegitimacionEntities context = new LegitimacionEntities();
        var query = context.ResultadoBusquedaOfac.Include("OFAC_SDN").Where(us =&gt; us.ent_num.Equals(10)).First();

        MessageBox.Show(query.SDN_Name);
    }
}

}

向我抛出以下错误: 

指定的包含路径无效。EntityType 'LegitimacionModel.ResultadoBusquedaOfac' 未声明名为 'OFAC_SDN' 的导航属性。

除此之外,我还必须通过数据服务或 WCF 传递数据,现在我这样做是为了首先证明关系很好,然后再将其传递给上面。

非常感谢您,我欢迎您的评论...

快乐的时光



4

0 回答 0