_Samples/Example_Entity.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
using System.Data.Common;
using System.Security.Cryptography;

//<doc:using>
using ComLib;
using ComLib.Entities;
using ComLib.ValidationSupport;
using ComLib.Application;
//</doc:using>
using ComLib.Account;


namespace ComLib.Samples
{
    /// <summary>
    /// Example for the Entities namespace.
    /// </summary>
    public class Example_Entity : App
    {
		//<doc:example>
        /// <summary>
        /// Run the application.
        /// </summary>
        public override BoolMessageItem Execute()
        {
            Console.WriteLine("====================================================");
            Console.WriteLine("Entity ");

            // Example 1 : Using Entity base class.
            IEntity entity = new Person() { Name = "kishore" };
            Console.WriteLine("Id, Persistant and Audit fields.");
            Console.WriteLine("These fields are set by EntityService if using CommonLibrary Entity-Model Services.");
            Console.WriteLine("Id            ", entity.Id);
            Console.WriteLine("IsPersistant  ", entity.IsPersistant());            
            Console.WriteLine("CreateDate    ", entity.CreateDate);
            Console.WriteLine("CreateUser    ", entity.CreateUser);
            Console.WriteLine("UpdateDate    ", entity.UpdateDate);
            Console.WriteLine("UpdateUser    ", entity.UpdateUser);
            Console.WriteLine("UpdateComment ", entity.UpdateComment);
            
            // Example 2 : Using Entity<T> generic base class to get the parameterless CRUD methods.
            // 1st initialize the repositories.
            EntityRegistration.Register<Person2>(new RepositoryInMemory<Person2>("Id"), false);
            var p2 = new Person2() { Name = "kishore" };
            p2.Create();
            p2.Name = "updated";
            p2.Update();
            p2.GetAll();
            p2.Save();
            p2.Delete();
            
            // Example 3 : Implement IEntityVersionable to get versioning on the entities.
            // Wrap the real repository w/ the RepositoryVersionable decorator to get versioning behaviour.
            EntityRegistration.Register<Person3>(new RepositoryVersioned<Person3>(new RepositoryInMemory<Person3>("Id,Version,VersionRefId")), false);
后面还有 107 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。