none
刚刚接触linq,能不能直接绑定数据到控件 RRS feed

  • 问题

  • linq查询出来的包含外键对象的列表怎么直接绑定到数据控件?

    var q=from user in db.users select user 在linq生成的cs文件中有两个类

    	public partial class userfile : INotifyPropertyChanging, INotifyPropertyChanged
    	{
    		
    		private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
    		
    		private int _fileID;
    		
    		private int _adminID;
    		
    	
    		private EntityRef<RF_admin> _RF_admin;
    		
      #region Extensibility Method Definitions
      partial void OnLoaded();
      partial void OnValidate(System.Data.Linq.ChangeAction action);
      partial void OnCreated();
      partial void OnfileIDChanging(int value);
      partial void OnfileIDChanged();
      partial void OnadminIDChanging(int value);
      partial void OnadminIDChanged();
    
      #endregion
    		
    		public userfile()
    		{
    			this._RF_admin = default(EntityRef<RF_admin>);
    			OnCreated();
    		}
    		
    		[Column(Storage="_fileID", DbType="Int NOT NULL", IsPrimaryKey=true)]
    		public int fileID
    		{
    			get
    			{
    				return this._fileID;
    			}
    			set
    			{
    				if ((this._fileID != value))
    				{
    					this.OnfileIDChanging(value);
    					this.SendPropertyChanging();
    					this._fileID = value;
    					this.SendPropertyChanged("fileID");
    					this.OnfileIDChanged();
    				}
    			}
    		}
    		
    		[Column(Storage="_adminID", DbType="Int NOT NULL")]
    		public int adminID
    		{
    			get
    			{
    				return this._adminID;
    			}
    			set
    			{
    				if ((this._adminID != value))
    				{
    					if (this._RF_admin.HasLoadedOrAssignedValue)
    					{
    						throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
    					}
    					this.OnadminIDChanging(value);
    					this.SendPropertyChanging();
    					this._adminID = value;
    					this.SendPropertyChanged("adminID");
    					this.OnadminIDChanged();
    				}
    			}
    		}		
    		[Association(Name="RF_admin_userfile", Storage="_RF_admin", ThisKey="adminID", OtherKey="adminID", IsForeignKey=true)]
    		public RF_admin RF_admin
    		{
    			get
    			{
    				return this._RF_admin.Entity;
    			}
    			set
    			{
    				RF_admin previousValue = this._RF_admin.Entity;
    				if (((previousValue != value) 
    							|| (this._RF_admin.HasLoadedOrAssignedValue == false)))
    				{
    					this.SendPropertyChanging();
    					if ((previousValue != null))
    					{
    						this._RF_admin.Entity = null;
    						previousValue.userfiles.Remove(this);
    					}
    					this._RF_admin.Entity = value;
    					if ((value != null))
    					{
    						value.userfiles.Add(this);
    						this._adminID = value.adminID;
    					}
    					else
    					{
    						this._adminID = default(int);
    					}
    					this.SendPropertyChanged("RF_admin");
    				}
    			}
    		}
    		
    		public event PropertyChangingEventHandler PropertyChanging;
    		
    		public event PropertyChangedEventHandler PropertyChanged;
    		
    		protected virtual void SendPropertyChanging()
    		{
    			if ((this.PropertyChanging != null))
    			{
    				this.PropertyChanging(this, emptyChangingEventArgs);
    			}
    		}
    		
    		protected virtual void SendPropertyChanged(String propertyName)
    		{
    			if ((this.PropertyChanged != null))
    			{
    				this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    			}
    		}
    	}
    能直接返回q.ToList()吗?返回了怎么绑定关联的RF_ADMIN 属性?
    2010年4月28日 6:30

答案

全部回复