实体框架函数不返回任何内容

时间:2013-05-27 11:24:38

标签: c# entity-framework

这是我的代码:

http://i43.tinypic.com/acpgdd.jpg

entities = new SamaEntities();
var institute_ContractInstitute = entities.ContractInstitutes;

我在观看页面中收到此错误

  

institute_ContractInstitute名称'institute_ContractInstitute'   在当前上下文中不存在

这是什么意思?

这是ContractInstitute Class:

public partial class ContractInstitute : EntityObject
    {
        #region Factory Method

        /// <summary>
        /// Create a new ContractInstitute object.
        /// </summary>
        /// <param name="id">Initial value of the Id property.</param>
        /// <param name="contractId">Initial value of the ContractId property.</param>
        /// <param name="instituteId">Initial value of the InstituteId property.</param>
        /// <param name="status">Initial value of the Status property.</param>
        /// <param name="level">Initial value of the Level property.</param>
        /// <param name="user_">Initial value of the User_ property.</param>
        public static ContractInstitute CreateContractInstitute(global::System.Int32 id, global::System.Int32 contractId, global::System.Int32 instituteId, global::System.Int16 status, global::System.Int16 level, global::System.Int32 user_)
        {
            ContractInstitute contractInstitute = new ContractInstitute();
            contractInstitute.Id = id;
            contractInstitute.ContractId = contractId;
            contractInstitute.InstituteId = instituteId;
            contractInstitute.Status = status;
            contractInstitute.Level = level;
            contractInstitute.User_ = user_;
            return contractInstitute;
        }

        #endregion

        #region Primitive Properties

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 Id
        {
            get
            {
                return _Id;
            }
            set
            {
                if (_Id != value)
                {
                    OnIdChanging(value);
                    ReportPropertyChanging("Id");
                    _Id = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("Id");
                    OnIdChanged();
                }
            }
        }
        private global::System.Int32 _Id;
        partial void OnIdChanging(global::System.Int32 value);
        partial void OnIdChanged();

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public Nullable<global::System.Double> Price
        {
            get
            {
                return _Price;
            }
            set
            {
                OnPriceChanging(value);
                ReportPropertyChanging("Price");
                _Price = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("Price");
                OnPriceChanged();
            }
        }
        private Nullable<global::System.Double> _Price;
        partial void OnPriceChanging(Nullable<global::System.Double> value);
        partial void OnPriceChanged();

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 ContractId
        {
            get
            {
                return _ContractId;
            }
            set
            {
                OnContractIdChanging(value);
                ReportPropertyChanging("ContractId");
                _ContractId = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("ContractId");
                OnContractIdChanged();
            }
        }
        private global::System.Int32 _ContractId;
        partial void OnContractIdChanging(global::System.Int32 value);
        partial void OnContractIdChanged();

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 InstituteId
        {
            get
            {
                return _InstituteId;
            }
            set
            {
                OnInstituteIdChanging(value);
                ReportPropertyChanging("InstituteId");
                _InstituteId = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("InstituteId");
                OnInstituteIdChanged();
            }
        }
        private global::System.Int32 _InstituteId;
        partial void OnInstituteIdChanging(global::System.Int32 value);
        partial void OnInstituteIdChanged();

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int16 Status
        {
            get
            {
                return _Status;
            }
            set
            {
                OnStatusChanging(value);
                ReportPropertyChanging("Status");
                _Status = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("Status");
                OnStatusChanged();
            }
        }
        private global::System.Int16 _Status;
        partial void OnStatusChanging(global::System.Int16 value);
        partial void OnStatusChanged();

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public Nullable<global::System.Double> CouncilPrice
        {
            get
            {
                return _CouncilPrice;
            }
            set
            {
                OnCouncilPriceChanging(value);
                ReportPropertyChanging("CouncilPrice");
                _CouncilPrice = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("CouncilPrice");
                OnCouncilPriceChanged();
            }
        }
        private Nullable<global::System.Double> _CouncilPrice;
        partial void OnCouncilPriceChanging(Nullable<global::System.Double> value);
        partial void OnCouncilPriceChanged();

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public Nullable<global::System.Int32> CurrencyId
        {
            get
            {
                return _CurrencyId;
            }
            set
            {
                OnCurrencyIdChanging(value);
                ReportPropertyChanging("CurrencyId");
                _CurrencyId = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("CurrencyId");
                OnCurrencyIdChanged();
            }
        }
        private Nullable<global::System.Int32> _CurrencyId;
        partial void OnCurrencyIdChanging(Nullable<global::System.Int32> value);
        partial void OnCurrencyIdChanged();

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int16 Level
        {
            get
            {
                return _Level;
            }
            set
            {
                OnLevelChanging(value);
                ReportPropertyChanging("Level");
                _Level = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("Level");
                OnLevelChanged();
            }
        }
        private global::System.Int16 _Level;
        partial void OnLevelChanging(global::System.Int16 value);
        partial void OnLevelChanged();

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 User_
        {
            get
            {
                return _User_;
            }
            set
            {
                OnUser_Changing(value);
                ReportPropertyChanging("User_");
                _User_ = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("User_");
                OnUser_Changed();
            }
        }
        private global::System.Int32 _User_;
        partial void OnUser_Changing(global::System.Int32 value);
        partial void OnUser_Changed();

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public Nullable<global::System.Int32> UserDelegate_
        {
            get
            {
                return _UserDelegate_;
            }
            set
            {
                OnUserDelegate_Changing(value);
                ReportPropertyChanging("UserDelegate_");
                _UserDelegate_ = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("UserDelegate_");
                OnUserDelegate_Changed();
            }
        }
        private Nullable<global::System.Int32> _UserDelegate_;
        partial void OnUserDelegate_Changing(Nullable<global::System.Int32> value);
        partial void OnUserDelegate_Changed();

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public Nullable<global::System.Int32> UserLoginAz_
        {
            get
            {
                return _UserLoginAz_;
            }
            set
            {
                OnUserLoginAz_Changing(value);
                ReportPropertyChanging("UserLoginAz_");
                _UserLoginAz_ = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("UserLoginAz_");
                OnUserLoginAz_Changed();
            }
        }
        private Nullable<global::System.Int32> _UserLoginAz_;
        partial void OnUserLoginAz_Changing(Nullable<global::System.Int32> value);
        partial void OnUserLoginAz_Changed();

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public Nullable<global::System.Double> HoldingPrice
        {
            get
            {
                return _HoldingPrice;
            }
            set
            {
                OnHoldingPriceChanging(value);
                ReportPropertyChanging("HoldingPrice");
                _HoldingPrice = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("HoldingPrice");
                OnHoldingPriceChanged();
            }
        }
        private Nullable<global::System.Double> _HoldingPrice;
        partial void OnHoldingPriceChanging(Nullable<global::System.Double> value);
        partial void OnHoldingPriceChanged();

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public Nullable<global::System.Double> CouncilHoldingPrice
        {
            get
            {
                return _CouncilHoldingPrice;
            }
            set
            {
                OnCouncilHoldingPriceChanging(value);
                ReportPropertyChanging("CouncilHoldingPrice");
                _CouncilHoldingPrice = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("CouncilHoldingPrice");
                OnCouncilHoldingPriceChanged();
            }
        }
        private Nullable<global::System.Double> _CouncilHoldingPrice;
        partial void OnCouncilHoldingPriceChanging(Nullable<global::System.Double> value);
        partial void OnCouncilHoldingPriceChanged();

        #endregion


        #region Navigation Properties

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("SamaModel", "ConInsGroup", "Group")]
        public EntityCollection<Group> Groups
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Group>("SamaModel.ConInsGroup", "Group");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<Group>("SamaModel.ConInsGroup", "Group", value);
                }
            }
        }

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("SamaModel", "ContractContractInstitute", "Contract")]
        public Contract Contract
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Contract>("SamaModel.ContractContractInstitute", "Contract").Value;
            }
            set
            {
                ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Contract>("SamaModel.ContractContractInstitute", "Contract").Value = value;
            }
        }
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [BrowsableAttribute(false)]
        [DataMemberAttribute()]
        public EntityReference<Contract> ContractReference
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Contract>("SamaModel.ContractContractInstitute", "Contract");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Contract>("SamaModel.ContractContractInstitute", "Contract", value);
                }
            }
        }

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("SamaModel", "InstituteContractInstitute", "Institute")]
        public Institute Institute
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Institute>("SamaModel.InstituteContractInstitute", "Institute").Value;
            }
            set
            {
                ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Institute>("SamaModel.InstituteContractInstitute", "Institute").Value = value;
            }
        }
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [BrowsableAttribute(false)]
        [DataMemberAttribute()]
        public EntityReference<Institute> InstituteReference
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Institute>("SamaModel.InstituteContractInstitute", "Institute");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Institute>("SamaModel.InstituteContractInstitute", "Institute", value);
                }
            }
        }

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("SamaModel", "CurrencyContractInstitute", "Currency")]
        public Currency Currency
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Currency>("SamaModel.CurrencyContractInstitute", "Currency").Value;
            }
            set
            {
                ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Currency>("SamaModel.CurrencyContractInstitute", "Currency").Value = value;
            }
        }
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [BrowsableAttribute(false)]
        [DataMemberAttribute()]
        public EntityReference<Currency> CurrencyReference
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Currency>("SamaModel.CurrencyContractInstitute", "Currency");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Currency>("SamaModel.CurrencyContractInstitute", "Currency", value);
                }
            }
        }

        #endregion

    }

2 个答案:

答案 0 :(得分:0)

  

我在观看页面中收到此错误

     

当前上下文中不存在名称“institute_ContractInstitute”

这正是它所说的内容:当前上下文中没有名称为institute_ContractInstitute的变量,即您的程序当前所在的位置。

var institute_ContractInstitute = ...之后放置断点,然后您可以在Watch窗口中检查其内容。

答案 1 :(得分:0)

可能这个问题是由于延迟加载造成的。 entity.ContractInstitutes中的任何数据都没有被加载。尝试使用List&lt;&gt;输入变量并使用.ToList()将ContractInstitutes放入列表中。