⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entity.cs

📁 用于c#.net数据库操作的类库。能把结婚集以数组的形成操作。
💻 CS
字号:
using System;
using System.IO;
using System.Data;
using System.Collections;	
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Remoting.Contexts;

namespace EnterpriseObjects
{
	public class Entity :DbParams, ISerializable
	{
		// members...
		private object[] _data;
		protected static Hashtable _serviceObjects;
		protected string _TableName="";
		protected string _ColumnId="";

		// exceptions...
		public class SaveChangesNotImplementedException : NotImplementedException
		{
			public SaveChangesNotImplementedException() : base("SaveChanges not implemented")
			{
			}
		}
														  
		public Entity()
		{
		}

		// ServiceObject - return our service object...
		protected static Service GetServiceObject(Type serviceObjectType)
		{
			// do we have the cache?
			if(_serviceObjects == null)
				_serviceObjects = new Hashtable();

			// get it out of the cache...
			Service serviceObject = (Service)_serviceObjects[serviceObjectType];
			if(serviceObject == null)
			{
				ServiceObjectFactory factory = EnterpriseApplication.Application.ServiceObjectFactory;
				serviceObject = factory.Create(serviceObjectType);

				// add it...
				_serviceObjects.Add(serviceObjectType, serviceObject);
			}
		
			return serviceObject;
		}
		public string TableName
		{
			get
			{
				return _TableName;
			}
		}
		public string ColumnId
		{
			get
			{
				return _ColumnId;
			}
		}

		// Data property...
		public object this[int index]
		{
			get
			{
				return _data[index];
			}
			set
			{
				_data[index] = value;
			}
		}

		// Populate - set the data for the entity...
		public override void Populate(DataRow row)
		{
			base.Populate(row);
			// store the data...
			_data = new object[row.ItemArray.Length];
			row.ItemArray.CopyTo(_data, 0);
		}
        //2003-5-29 law add
        public object[] ToArray
        {
            get {return  _data;}
        }
        //----------\
		public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
		{
			if(_data != null)
			{
				info.AddValue("Row", _data, typeof(object[]));
				}
			else
			{
				info.AddValue("Row", null, typeof(object[]));
				}
		}

		protected Entity(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
		{
			_data = (object[])info.GetValue("Row", typeof(object[]));
			
		}
		public virtual Entity GetById(string id)
		{
			DbParams dbp=new DbParams();
			dbp[this.ColumnId]=id;
			return GetById(dbp);
		}
		public virtual Entity GetById(DbParams dbp)
		{
			return this.Service.GetById(TableName,ColumnId,dbp.GetProperty(ColumnId,""),typeof(EntitySet));
		}
		public virtual Entity Insert()
		{
			return null;
		}
		public virtual int Delete()
		{
			return 0;
		}
		// SaveChanges..
		public virtual void SaveChanges()
		{
			throw new NotImplementedException();
		}

		public bool IsNull(int index)
		{
			if(this[index] == DBNull.Value)
				return true;
			else
				return false;
		}

		public void SetToNull(int index)
		{
			this[index] = DBNull.Value;
		}

		public void Serialize(string filename)
		{
			FileStream stream = new FileStream(filename, FileMode.Create);
			Serialize(stream);
			stream.Close();
		}

		public void Serialize(Stream stream)
		{
			// formatter...
			BinaryFormatter formatter = new BinaryFormatter();
			Serialize(stream, formatter);
		}

		public void Serialize(Stream stream, IFormatter formatter)
		{
			formatter.Serialize(stream, this);
		}

		public void Serialize(string filename, IFormatter formatter)
		{
			FileStream stream = new FileStream(filename, FileMode.Create);
			Serialize(stream, formatter);
			stream.Close();
		}

		// Deserialize - retrieve from a stream...
		public static EntitySet Deserialize(string filename)
		{
			FileStream stream = new FileStream(filename, FileMode.Open);
			EntitySet newEntitySet = Deserialize(stream);
			stream.Close();
			return newEntitySet;
		}

		public static EntitySet Deserialize(Stream stream)
		{
			// formatter...
			BinaryFormatter formatter = new BinaryFormatter();
			EntitySet newEntitySet = Deserialize(stream, formatter);
			return newEntitySet;
		}

		public static EntitySet Deserialize(string filename, IFormatter formatter)
		{
			FileStream stream = new FileStream(filename, FileMode.Open);
			EntitySet myObject = (EntitySet)Deserialize(stream, formatter);
			stream.Close();
			return myObject;
		}

		public static EntitySet Deserialize(Stream stream, IFormatter formatter)
		{
			EntitySet myObject = (EntitySet)formatter.Deserialize(stream);
			return myObject;
		}

		public bool SupportsConcurrency()
		{
			if(this is IConcurrentEntity)
				return true;
			else
				return false;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -