using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Xml.Serialization;
using NewLife;
using NewLife.Data;
using NewLife.Log;
using NewLife.Model;
using NewLife.Reflection;
using NewLife.Threading;
using NewLife.Web;
using XCode;
using XCode.Cache;
using XCode.Configuration;
using XCode.DataAccessLayer;
using XCode.Membership;
namespace XCode.Demo
{
/// <summary>示例</summary>
public partial class DemoEntity : Entity<DemoEntity>
{
#region 对象æ“作
static DemoEntity()
{
// ç´¯åŠ å—段
//Meta.Factory.AdditionalFields.Add(__.Logins);
// 过滤器 UserModuleã€TimeModuleã€IPModule
Meta.Modules.Add<TimeModule>();
}
/// <summary>验è¯æ•°æ®ï¼Œé€šè¿‡æŠ›å‡ºå¼‚常的方å¼æ示验è¯å¤±è´¥ã€‚</summary>
/// <param name="isNew">是å¦æ’å…¥</param>
public override void Valid(Boolean isNew)
{
// 如果没有è„æ•°æ®ï¼Œåˆ™ä¸éœ€è¦è¿›è¡Œä»»ä½•å¤„ç†
if (!HasDirty) return;
// 在新æ’入数æ®æˆ–者修改了指定å—段时进行修æ£
//if (isNew && !Dirtys[nameof(CreateTime)]) nameof(CreateTime) = DateTime.Now;
}
///// <summary>首次连接数æ®åº“æ—¶åˆå§‹åŒ–æ•°æ®ï¼Œä»…用于实体类é‡è½½ï¼Œç”¨æˆ·ä¸åº”该调用该方法</summary>
//[EditorBrowsable(EditorBrowsableState.Never)]
//protected override void InitData()
//{
// // InitData一般用于当数æ®è¡¨æ²¡æœ‰æ•°æ®æ—¶æ·»åŠ 一些默认数æ®ï¼Œè¯¥å®žä½“类的任何第一次数æ®åº“æ“作都会触å‘该方法,默认异æ¥è°ƒç”¨
// if (Meta.Count > 0) return;
// if (XTrace.Debug) XTrace.WriteLine("开始åˆå§‹åŒ–DemoEntity[示例]æ•°æ®â€¦â€¦");
// var entity = new DemoEntity();
// entity.ID = 0;
// entity.Name = "abc";
// entity.CreateTime = DateTime.Now;
// entity.Insert();
// if (XTrace.Debug) XTrace.WriteLine("完æˆåˆå§‹åŒ–DemoEntity[示例]æ•°æ®ï¼"
//}
///// <summary>å·²é‡è½½ã€‚基类先调用Valid(true)验è¯æ•°æ®ï¼Œç„¶åŽåœ¨äº‹åŠ¡ä¿æŠ¤å†…调用OnInsert</summary>
///// <returns></returns>
//public override Int32 Insert()
//{
// return base.Insert();
//}
///// <summary>å·²é‡è½½ã€‚在事务ä¿æŠ¤èŒƒå›´å†…处ç†ä¸šåŠ¡ï¼Œä½äºŽValid之åŽ</summary>
///// <returns></returns>
//protected override Int32 OnDelete()
//{
// return base.OnDelete();
//}
#endregion
#region 扩展属性
#endregion
#region 扩展查询
/// <summary>æ ¹æ®ç¼–å·æŸ¥æ‰¾</summary>
/// <param name="id">ç¼–å·</param>
/// <returns>实体对象</returns>
public static DemoEntity FindByID(Int32 id)
{
if (id <= 0) return null;
// 实体缓å˜
if (Meta.Count < 1000) return Meta.Cache.Entities.FirstOrDefault(e => e.ID == id);
// å•å¯¹è±¡ç¼“å˜
//return Meta.SingleCache[id];
return Find(_.ID == id);
}
#endregion
#region 高级查询
#endregion
#region 业务æ“作
#endregion
}
}
|