views:

15

answers:

0

Hi, I have 82 procedures that create data tables, and i want to iterate through this tables and dynamically create the following classes for each data table: * The data table contain two columns: Id, Desc. e.g. CountryId, CountryDesc. * Each of the bold items in the example class below is dynamically create based on the data table i am using.

using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Data.SqlClient; using System.Linq; using System.Linq.Expressions; using RM.Common.ExtesionMethods; using RM.DataLibrary; using RM.DataLibrary.Interfaces; using RM.Entity;

namespace RM.LookUpManager.Object { public class Countrylist : BaseEntity { public int CountryId { get; set; }

    **public string CountryDesc { get; set; }**

    **public int SortOrder { get; set; }**

    public string GetLuTextById(int id)
    {
        var returnStr = "";

        var **countrylist**Obj = GetObject();
        if (**countrylist**Obj == null)
        {
            CreateObject();
            GetLuTextById(id);
        }
        else
        {
            var data = **countrylist**Obj.EntitiesDataList;
            returnStr = data.Where(c => c.**CountryId** == id).Select(c => c.**CountryDesc**).SingleOrDefault();
        }
        return returnStr;
    }

    public IEnumerable<**Countrylist**> GetLuSubListById(int id)
    {
        IEnumerable<**Countrylist**> returnEnumerable = null;

        var countrylistObj = GetObject();
        if (countrylistObj == null)
        {
            CreateObject();
            GetLuTextById(id);
        }
        else
        {
            var data = **countrylist**Obj.EntitiesDataList;
            returnEnumerable = data.Where(c => c.**CountryId** == id);
        }
        return returnEnumerable;
    }

    public **CoutryList**OfEntities GetObject()
    {
        Expression<Func<**CoutryList**OfEntities, bool>> entity = (p) => p.EntityId == "**Countrylist**";

        return EntityManager.Instance.Single(entity);
    }

    public List<**Countrylist**> CreateObject()
    {
        IDatabase db = new Database(@"Server=test;Database=testDB;User=sa;Password=test;", "System.Data.SqlClient");
        var list = new List<**Countrylist**>();
        var args = new List<DbParameter> { db.BuildInParam("LangId", DbType.String, "ENU") };

        db.ExecuteReader("**sp_GetCountryList**", CommandType.StoredProcedure, reader =>
        {
            var t = new EntityFiller<**Countrylist**>();

            reader.Read();

            list = t.Fill(reader);

        }, args.ToArray());

        var **coutryList**OfEntities = new **CoutryList**OfEntities { EntitiesDataList = list, EntityId = "**Countrylist**" };
        EntityManager.Instance.AddEntity(**coutryList**OfEntities);

        return list;
    }

    public override void Update(float elapsedTime)
    {}
}

public class **CoutryList**OfEntities : BaseEntity
{
    public List<**Countrylist**> EntitiesDataList { get; set; }
    public string EntityId { get; set; }

    public override void Update(float elapsedTime)
    {}
}

}

Thanks..