1

这是我的代码:

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

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

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

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

这是什么意思?

这是 ContractInstitute 类:

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

    }
4

2 回答 2

0

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

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

这正是它所说的:institute_ContractInstitute在当前上下文中不存在具有该名称的变量,即您的程序当前所在的位置。

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

于 2013-05-27T11:38:24.260 回答
0

问题可能是由于延迟加载。entity.ContractInstitutes 中的任何数据都没有被加载。尝试使用 List<> 类型变量并使用 .ToList() 将 ContractInstitutes 放入列表中。

于 2013-05-27T11:43:13.993 回答