Creating an ORM in C# - Part 4

6/25/2009

Part 1 - Defining our classes
Part 2 - Reflection and class analysis
Part 3 - Creating our database and tables

If you have yet to read the first three parts of this series, go back and do so. Not because the code in this section isn't readable without it, but because each article builds on the ones before it. Anyway, today I'm showing the stored procedures that the system defines as well as the insert/saving and selecting of an item.

Anyway, in the last article, we used an IStatement class called CreateTable in our building of the SQL to build each table. It has been modified slightly if you go back and look at it but it's generally the same as in the last article. Anyway, along with creating a table, we can define four functions that the system will need to be able to do, insert, update, delete, and select. With the exception of the select statements, these functions really aren't going to change much and as such I've decided that instead of creating the functions each time, I would simply use stored procedures. So let's look at how the stored procedures are created:

   1: internal static class SQLBuilder
   2: {
   3:     public static void CreateStoredProcedures(string ConnectionString, Class Class, ClassManager Manager, bool RecreateIfExists)
   4:     {
   5:         CreateInsertStoredProcedures(ConnectionString, Class, Manager);
   6:         CreateUpdateStoredProcedures(ConnectionString, Class, Manager);
   7:         CreateDeleteStoredProcedures(ConnectionString, Class, Manager);
   8:         CreateSelectStoredProcedures(ConnectionString, Class, Manager);
   9:     } 
  10:  
  11:     private static void CreateSelectStoredProcedures(string ConnectionString, Class Class, ClassManager Manager)
  12:     {
  13:         bool Exists = false;
  14:         string ClassName = Class.OriginalType.Name;
  15:         Utilities.SQLHelper.SQLHelper Helper = new Utilities.SQLHelper.SQLHelper("Select * from sys.Procedures where name=@ProcedureName", ConnectionString, CommandType.Text);
  16:         if (!Exists)
  17:         {
  18:             Select SelectStoredProcedures = new Select(Class, Manager);
  19:             Helper.Command = SelectStoredProcedures.ToString();
  20:             try
  21:             {
  22:                 Helper.Open();
  23:                 Helper.ExecuteNonQuery();
  24:             }
  25:             catch { }
  26:             finally { Helper.Close(); }
  27:         }
  28:     } 
  29:  
  30:     private static void CreateDeleteStoredProcedures(string ConnectionString, Class Class, ClassManager Manager)
  31:     {
  32:         bool Exists = false;
  33:         string ClassName = Class.OriginalType.Name;
  34:         Utilities.SQLHelper.SQLHelper Helper = new Utilities.SQLHelper.SQLHelper("Select * from sys.Procedures where name=@ProcedureName", ConnectionString, CommandType.Text);
  35:         if (!Exists)
  36:         {
  37:             Delete DeleteStoredProcedures = new Delete(Class, Manager);
  38:             Helper.Command = DeleteStoredProcedures.ToString();
  39:             try
  40:             {
  41:                 Helper.Open();
  42:                 Helper.ExecuteNonQuery();
  43:             }
  44:             catch { }
  45:             finally { Helper.Close(); }
  46:         }
  47:     } 
  48:  
  49:     private static void CreateUpdateStoredProcedures(string ConnectionString, Class Class, ClassManager Manager)
  50:     {
  51:         bool Exists = false;
  52:         string ClassName = Class.OriginalType.Name;
  53:         Utilities.SQLHelper.SQLHelper Helper = new Utilities.SQLHelper.SQLHelper("Select * from sys.Procedures where name=@ProcedureName", ConnectionString, CommandType.Text);
  54:         if (!Exists)
  55:         {
  56:             Update UpdateStoredProcedures = new Update(Class, Manager);
  57:             Helper.Command = UpdateStoredProcedures.ToString();
  58:             try
  59:             {
  60:                 Helper.Open();
  61:                 Helper.ExecuteNonQuery();
  62:             }
  63:             catch { }
  64:             finally { Helper.Close(); }
  65:         }
  66:     } 
  67:  
  68:     private static void CreateInsertStoredProcedures(string ConnectionString, Class Class, ClassManager Manager)
  69:     {
  70:         bool Exists = false;
  71:         string ClassName = Class.OriginalType.Name;
  72:         Utilities.SQLHelper.SQLHelper Helper = new Utilities.SQLHelper.SQLHelper("Select * from sys.Procedures where name=@ProcedureName", ConnectionString, CommandType.Text);
  73:         if (!Exists)
  74:         {
  75:             Insert InsertStoredProcedures = new Insert(Class, Manager);
  76:             Helper.Command = InsertStoredProcedures.ToString();
  77:             try
  78:             {
  79:                 Helper.Open();
  80:                 Helper.ExecuteNonQuery();
  81:             }
  82:             catch { }
  83:             finally { Helper.Close(); }
  84:         }
  85:     } 
  86:  
  87:     public static void CreateTable(string ConnectionString, Class Class, ClassManager Manager, bool RecreateIfExists)
  88:     {
  89:         bool Exists = false;
  90:         string ClassName = Class.OriginalType.Name;
  91:         Utilities.SQLHelper.SQLHelper Helper = new Utilities.SQLHelper.SQLHelper("Select * from sys.Tables where name=@TableID", ConnectionString, CommandType.Text);
  92:         if (!RecreateIfExists)
  93:         {
  94:             try
  95:             {
  96:                 Helper.Open();
  97:                 Helper.AddParameter("@TableID", ClassName, 200);
  98:                 Helper.ExecuteReader();
  99:                 if (Helper.Read())
 100:                 {
 101:                     Exists = true;
 102:                 }
 103:             }
 104:             catch { }
 105:             finally { Helper.Close(); }
 106:         }
 107:         if (!Exists)
 108:         {
 109:             CreateTable Table = new CreateTable(Class, Manager);
 110:             Helper.Command = Table.ToString();
 111:             try
 112:             {
 113:                 Helper.Open();
 114:                 Helper.ExecuteNonQuery();
 115:             }
 116:             catch { }
 117:             finally { Helper.Close(); }
 118:         }
 119:     } 
 120:  
 121:     public static void CreateDatabase(string ConnectionString, string DatabaseName, bool RecreateIfExists)
 122:     {
 123:         bool Exists = false;
 124:         Utilities.SQLHelper.SQLHelper Helper = new Utilities.SQLHelper.SQLHelper("SELECT * FROM Master.sys.Databases where name=@DatabaseID", ConnectionString, CommandType.Text);
 125:         if (!RecreateIfExists)
 126:         {
 127:             try
 128:             {
 129:                 Helper.Open();
 130:                 Helper.AddParameter("@DatabaseID", DatabaseName, 100);
 131:                 Helper.ExecuteReader();
 132:                 if (Helper.Read())
 133:                 {
 134:                     Exists = true;
 135:                 }
 136:             }
 137:             catch { }
 138:             finally { Helper.Close(); }
 139:         }
 140:         if (!Exists)
 141:         {
 142:             Helper.Command = "CREATE DATABASE " + DatabaseName.Replace("'", "");
 143:             try
 144:             {
 145:                 Helper.Open();
 146:                 Helper.ExecuteNonQuery();
 147:             }
 148:             catch { }
 149:             finally { Helper.Close(); }
 150:         }
 151:     } 
 152:  
 153:     internal static bool Save(string ConnectionString, object Object, Class ObjectDefinition, ClassManager ClassManager)
 154:     {
 155:         Utilities.SQLHelper.SQLHelper Helper = new Utilities.SQLHelper.SQLHelper("", ConnectionString, CommandType.Text);
 156:         Insert ObjectInsert = new Insert(ObjectDefinition, ClassManager);
 157:         ObjectInsert.Run(Object, Helper);
 158:         return false;
 159:     } 
 160:  
 161:     public static object SelectByID(string ConnectionString, object IDValue, Class Class, ClassManager Manager)
 162:     {
 163:         Utilities.SQLHelper.SQLHelper Helper = new Utilities.SQLHelper.SQLHelper("", ConnectionString, CommandType.Text);
 164:         Select TempSelect=new Select(Class,Manager);
 165:         return TempSelect.SelectByID(IDValue,Helper);
 166:     }
 167: } 
 168:  
 169: internal class Insert:IStatement
 170: {
 171:     public override string ToString()
 172:     {
 173:         StringBuilder Builder = new StringBuilder("EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE dbo." + _Class.OriginalType.Name + "_Insert\n");
 174:         StringBuilder ListBuilder = new StringBuilder();
 175:         string Splitter = "";
 176:         string Splitter2="";
 177:         StringBuilder Values=new StringBuilder();
 178:         StringBuilder Parameters=new StringBuilder();
 179:         foreach (IDataType Column in Columns)
 180:         {
 181:             if (Column != null && !Column.Type.Equals("List", StringComparison.CurrentCultureIgnoreCase))
 182:             {
 183:                 if (!string.IsNullOrEmpty(Column.CreateStoredProcedureParameter(false, true)))
 184:                 {
 185:                     Builder.Append(Splitter + Column.CreateStoredProcedureParameter(false, true));
 186:                     Values.Append(Splitter2 + Column.Name);
 187:                     Parameters.Append(Splitter2 + "@" + Column.Name);
 188:                     Splitter = ",\n";
 189:                     Splitter2 = ",";
 190:                 }
 191:             }
 192:             else if (Column != null && Column.Type.Equals("List", StringComparison.CurrentCultureIgnoreCase))
 193:             {
 194:                 ListBuilder.Append(" " + Column.CreateInsertCommand());
 195:             }
 196:         } 
 197:  
 198:         Builder.Append("\nAS\nINSERT INTO " + _Class.OriginalType.Name + "(" + Values.ToString() + ") VALUES (" + Parameters.ToString() + ")\nSELECT scope_identity() as [ID]\nRETURN'\n");
 199:         return Builder.ToString()+ListBuilder.ToString();
 200:     }
 201: }

The SQL builder is called by our provider that we created last time. The builder then goes off and creates our stored procedures (note that at this time it doesn't check to see if they exist first, that will be added later). The SQLBuilder then creates an Insert (or Update, Select, etc. object), passing it the class definition as well as the ClassManager. This class then parses out the information that it needs for each property of the class and builds up a string containing the stored procedure.

In the code above, it's the insert stored procedure that is created. You'll notice that it deals with lists in a different manner than the rest of the properties (note that we're still not dealing with classes). In order to represent a list effectively in a database, you really need to separate out that information in a separate table. As such, the list needs its own insert procedure (and its own delete and select stored procedures also). The code for this is within the List class:

   1: public override string CreateInsertCommand()
   2: {
   3:     StringBuilder Builder = new StringBuilder("EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE dbo." + Name + "_Insert\n");
   4:     string Splitter = "";
   5:     foreach(IDataType Column in Columns)
   6:     {
   7:         Builder.Append(Splitter + Column.CreateStoredProcedureParameter(false, true));
   8:         Splitter = ",\n";
   9:     }
  10:     Builder.Append("\nAS\nINSERT INTO "+Name+"(");
  11:     StringBuilder Values=new StringBuilder();
  12:     Splitter = "";
  13:     foreach(IDataType Column in Columns)
  14:     {
  15:         Values.Append(Splitter+"@"+Column.Name);
  16:         Builder.Append(Splitter+Column.Name);
  17:         Splitter=",";
  18:     }
  19:     Builder.Append(") VALUES(" + Values.ToString() + ")\nRETURN'\n");
  20:     return Builder.ToString();
  21: }

It's not pretty doing it this way and I'm sure that I'll figure another way to do this, but it is what it is for now. Anyway, we have similar code for update, delete, and select stored procedures (note that the select versions only deal with selecting an item by the ID field and selecting all of the items). These stored procedures and then thrown back to the SQLBuilder class and it runs it against the database.

So at this point we have our tables, our stored procedures, etc. Now how do we actually insert something into our database? Well in order to do this I've created a helper class called Session:

   1: public class Session
   2: {
   3:     public Session()
   4:     {
   5:     } 
   6:  
   7:     internal Session(IProvider Provider)
   8:     {
   9:         _Provider = Provider;
  10:     } 
  11:  
  12:     public bool Save(object Object)
  13:     {
  14:         if (_Provider != null)
  15:         {
  16:             return _Provider.Save(Object);
  17:         }
  18:         return false;
  19:     } 
  20:  
  21:     public void Select<T>(object ID, out T Object)
  22:     {
  23:         if (_Provider != null)
  24:         {
  25:             Object= (T)_Provider.SelectByID<T>(ID);
  26:             return;
  27:         }
  28:         Object = default(T);
  29:     } 
  30:  
  31:     public void Delete(object Object)
  32:     {
  33:         if (_Provider != null)
  34:         {
  35:             _Provider.Delete(Object);
  36:         }
  37:     } 
  38:  
  39:     private IProvider _Provider=null;
  40: }

As you can see, all it really does is acts as a provider proxy between us and the provider. The two functions that you will want to take a look at are Save and Select. The Save function is pretty straightforward but the Select statement takes a bit more explaining. In the Save function's case, we can get the Type of the object at any time and discover what we should be selecting since we have our ClassManager already set up. In the case of the Select though, we don't know what we're suppose to be selecting. So in order to help, we use generics here. That way we can pull the Type class appropriately and pass that to our ClassManager to find out what to do.

Anyway, if we look back at the Provider class:

   1: class Provider : IProvider
   2: {
   3:     internal override bool Save(object Object)
   4:     {
   5:         Class TempClassDefinition = null;
   6:         try
   7:         {
   8:             TempClassDefinition = ClassManager[Object.GetType()];
   9:         }
  10:         catch { TempClassDefinition = null; }
  11:         return SQLBuilder.Save(ConnectionString, Object, TempClassDefinition, ClassManager);
  12:     } 
  13:  
  14:     internal override object SelectByID<T>(object IDValue)
  15:     {
  16:         Class TempClassDefinition = null;
  17:         try
  18:         {
  19:             TempClassDefinition = ClassManager[typeof(T)];
  20:         }
  21:         catch { TempClassDefinition = null; }
  22:         return SQLBuilder.SelectByID(ConnectionString, IDValue, TempClassDefinition, ClassManager);
  23:     }
  24: }

You will notice that all it does is passes it on to the SQLBuilder class. The SQLBuilder class in turn simply creates an Insert/Select class depending on what is called and runs a function. Note that at this point Save only inserts items, but when Update is implemented it would check the ID and call the appropriate class here.

The Insert class uses the following functions to actually go about and insert the information:

   1: public override void Run(object Object, SQLHelper Helper)
   2: {
   3:     Type ObjectType = Object.GetType();
   4:     try
   5:     {
   6:         Helper.Command = _Class.OriginalType.Name + "_Insert";
   7:         Helper.CommandType = CommandType.StoredProcedure;
   8:         Helper.Open();
   9:         SetupProperties(Object, Helper, ObjectType);
  10:         object IDValue=Helper.ExecuteScalar();
  11:         SetID(Object, ObjectType, IDValue);
  12:     }
  13:     catch { }
  14:     finally { Helper.Close(); }
  15:     SetupLists(Object, Helper, ObjectType);
  16: } 
  17:  
  18: private void SetupLists(object Object, SQLHelper Helper, Type ObjectType)
  19: {
  20:     foreach (IDataType Column in Columns)
  21:     {
  22:         if (Column != null && Column.Type.Equals("List", StringComparison.CurrentCultureIgnoreCase))
  23:         {
  24:             string IDName=((List)Column).IDName;
  25:             SqlDbType IDType=((List)Column).IDType;
  26:             string DataName=((List)Column).DataName;
  27:             SqlDbType DataType=((List)Column).DataType;
  28:             int DataSize=((List)Column).Size; 
  29:  
  30:             PropertyInfo IDPropertyInfo = ObjectType.GetProperty(IDName);
  31:             object IDValue = IDPropertyInfo.GetValue(Object, null); 
  32:  
  33:             Helper.Command = Column.Name + "_Insert"; 
  34:  
  35:             PropertyInfo PropertyInfo = ObjectType.GetProperty(Column.Attribute.Name);
  36:             object ListValue = PropertyInfo.GetValue(Object, null);
  37:             Type ListType = ListValue.GetType();
  38:             PropertyInfo IndexProperty = ListType.GetProperty("Item");
  39:             PropertyInfo CountProperty = ListType.GetProperty("Count");
  40:             int Count = (int)CountProperty.GetValue(ListValue, null);
  41:             for (int x = 0; x < Count; ++x)
  42:             {
  43:                 try
  44:                 {
  45:                     Helper.Open();
  46:                     Helper.AddParameter("@" + IDName, IDValue, IDType);
  47:                     if (DataType == SqlDbType.NVarChar)
  48:                     {
  49:                         Helper.AddParameter("@" + DataName, (string)IndexProperty.GetValue(ListValue, new object[] { x }), DataSize);
  50:                     }
  51:                     else
  52:                     {
  53:                         Helper.AddParameter("@" + DataName, IndexProperty.GetValue(ListValue, new object[] { x }), DataType);
  54:                     }
  55:                     Helper.ExecuteNonQuery();
  56:                 }
  57:                 catch { }
  58:                 finally { Helper.Close(); }
  59:             }
  60:         }
  61:     }
  62: } 
  63:  
  64: private void SetupProperties(object Object, SQLHelper Helper, Type ObjectType)
  65: {
  66:     foreach (IDataType Column in Columns)
  67:     {
  68:         if (Column != null && !Column.Type.Equals("List", StringComparison.CurrentCultureIgnoreCase))
  69:         {
  70:             PropertyInfo PropertyInfo = ObjectType.GetProperty(Column.Name);
  71:             object Value = PropertyInfo.GetValue(Object, null);
  72:             if (Column is NVarChar && !Column.IsPrimaryKey)
  73:             {
  74:                 foreach (IConstraint Constraint in Column.Constraints)
  75:                 {
  76:                     if (Constraint is Size)
  77:                     {
  78:                         Helper.AddParameter("@" + Column.Name, (string)Value, ((Size)Constraint).Length);
  79:                         break;
  80:                     }
  81:                 }
  82:             }
  83:             else if (!Column.IsPrimaryKey)
  84:             {
  85:                 Helper.AddParameter("@" + Column.Name, Value, Column.DataType);
  86:             }
  87:         }
  88:     }
  89: } 
  90:  
  91: private void SetID(object Object, Type ObjectType, object IDValue)
  92: {
  93:     foreach (IDataType Column in Columns)
  94:     {
  95:         if (Column != null &&
  96:             !Column.Type.Equals("List", StringComparison.CurrentCultureIgnoreCase) &&
  97:             Column.IsPrimaryKey)
  98:         {
  99:             PropertyInfo PropertyInfo = ObjectType.GetProperty(Column.Name);
 100:             if (Column is Int)
 101:             {
 102:                 PropertyInfo.SetValue(Object, int.Parse(IDValue.ToString()), null);
 103:             }
 104:             else if (Column is UniqueIdentifier)
 105:             {
 106:                 PropertyInfo.SetValue(Object, new Guid(IDValue.ToString()), null);
 107:             }
 108:             break;
 109:         }
 110:     }
 111: }

The setup properties function uses some basic reflection to get each property's value and inserts it as a parameter with the exception of lists (once again, these have to be handled separately. We then run the stored procedure and get back the new ID (since we're auto generating these from the database for now) and setting the ID field of the class. We then go through each list and insert it's information. This is a bit more in depth as we have to get the List property, pull out a couple properties of the List (specifically Count and Item), and then set each item in the list up and run it separately...

But when all is said and done, we can simply call Save and our item is saved to the database. Now what about selecting it back out?

   1: public object SelectByID(object IDValue, SQLHelper Helper)
   2: {
   3:     Helper.Command = _Class.OriginalType.Name + "_Select";
   4:     Helper.CommandType = CommandType.StoredProcedure;
   5:     object ClassInstance = null;
   6:     IDataType IDField = null;
   7:     IDField = FindIDField(IDField);
   8:     ClassInstance = LoadMainClass(IDValue, Helper, ClassInstance, IDField);
   9:     ClassInstance = LoadLists(IDValue, Helper, ClassInstance, IDField);
  10:     return ClassInstance;
  11: } 
  12:  
  13: private object LoadLists(object IDValue, SQLHelper Helper, object ClassInstance, IDataType IDField)
  14: {
  15:     foreach (IDataType Column in Columns)
  16:     {
  17:         if (Column != null && Column.Type.Equals("List", StringComparison.CurrentCultureIgnoreCase))
  18:         {
  19:             PropertyInfo ColumnInfo = _Class.DerivedType.GetProperty(((List)Column).DataName);
  20:             Helper.Command = Column.Name + "_Select";
  21:             Helper.ClearParameters();
  22:             try
  23:             {
  24:                 Helper.Open();
  25:                 if (IDField is NVarChar)
  26:                 {
  27:                     foreach (IConstraint Constraint in IDField.Constraints)
  28:                     {
  29:                         if (Constraint is Size)
  30:                         {
  31:                             Helper.AddParameter("@" + IDField.Name, (string)IDValue, ((Size)Constraint).Length);
  32:                         }
  33:                     }
  34:                 }
  35:                 else
  36:                 {
  37:                     Helper.AddParameter("@" + IDField.Name, IDValue, IDField.DataType);
  38:                 }
  39:                 Helper.ExecuteReader(); 
  40:  
  41:                 ColumnInfo.SetValue(ClassInstance, Activator.CreateInstance(Column.Attribute.Type), null);
  42:                 object CurrentList = ColumnInfo.GetValue(ClassInstance, null);
  43:                 Type ListType = CurrentList.GetType();
  44:                 while (Helper.Read())
  45:                 {
  46:                     object ListItemValue=Helper.GetParameter(((List)Column).DataName,null);
  47:                     if (Column.Attribute.Type.GetGenericArguments()[0].FullName.Equals("System.Single", StringComparison.CurrentCultureIgnoreCase))
  48:                     {
  49:                         Column.Attribute.Type.InvokeMember("Add", BindingFlags.InvokeMethod, null, CurrentList, new object[] { float.Parse(ListItemValue.ToString()) });
  50:                     }
  51:                     else
  52:                     {
  53:                         Column.Attribute.Type.InvokeMember("Add", BindingFlags.InvokeMethod, null, CurrentList, new object[] { ListItemValue });
  54:                     }
  55:                 }
  56:             }
  57:             catch { }
  58:             finally
  59:             {
  60:                 Helper.Close();
  61:             }
  62:         }
  63:     }
  64:     return ClassInstance;
  65: } 
  66:  
  67: private IDataType FindIDField(IDataType IDField)
  68: {
  69:     foreach (IDataType Column in Columns)
  70:     {
  71:         if (Column != null && !Column.Type.Equals("List", StringComparison.CurrentCultureIgnoreCase))
  72:         {
  73:             if (Column.IsPrimaryKey)
  74:             {
  75:                 IDField = Column;
  76:                 break;
  77:             }
  78:         }
  79:     }
  80:     return IDField;
  81: } 
  82:  
  83: private object LoadMainClass(object IDValue, SQLHelper Helper, object ClassInstance, IDataType IDField)
  84: {
  85:     try
  86:     {
  87:         Helper.Open();
  88:         if (IDField is NVarChar)
  89:         {
  90:             foreach (IConstraint Constraint in IDField.Constraints)
  91:             {
  92:                 if (Constraint is Size)
  93:                 {
  94:                     Helper.AddParameter("@" + IDField.Name, (string)IDValue, ((Size)Constraint).Length);
  95:                 }
  96:             }
  97:         }
  98:         else
  99:         {
 100:             Helper.AddParameter("@" + IDField.Name, IDValue, IDField.DataType);
 101:         }
 102:         Helper.ExecuteReader();
 103:         if (Helper.Read())
 104:         {
 105:             ClassInstance = Activator.CreateInstance(_Class.DerivedType);
 106:             foreach (IDataType Column in Columns)
 107:             {
 108:                 if (Column != null && !Column.Type.Equals("List", StringComparison.CurrentCultureIgnoreCase))
 109:                 {
 110:                     PropertyInfo TempProperty = _Class.DerivedType.GetProperty(Column.Name);
 111:                     if (TempProperty.PropertyType.FullName.Equals("System.Single", StringComparison.CurrentCultureIgnoreCase))
 112:                     {
 113:                         TempProperty.SetValue(ClassInstance, float.Parse(Helper.GetParameter(Column.Name, null).ToString()), null);
 114:                     }
 115:                     else
 116:                     {
 117:                         TempProperty.SetValue(ClassInstance, Helper.GetParameter(Column.Name, null), null);
 118:                     }
 119:                 }
 120:             }
 121:         }
 122:     }
 123:     catch { }
 124:     finally { Helper.Close(); }
 125:     return ClassInstance;
 126: }

This is fairly similar. We first create our class object (using the Activator class) and then proceed to load the main (non list) portions of the class. You'll notice that there is a special case for floats. The reason for this is that they're singles and we're saving all of our floats as doubles within the database. This could be improved a bit by treating the various types as a bit more different instead of grouping them together.

Once that is loaded, we then go and load our lists. Once again we have to use a bit of reflection here to first create the list and then go and invoke the Add method on that list for each item. But that's the only portions that may cause some confusion.

Anyway, that's it really.  At this point we send back our newly created object to the user. I would show you the update and delete code but I'm still working on it. So download the code, take a look, leave feedback, and happy coding.



Comments

James Craig
July 07, 2010 10:39 AM

Actually the series was finished a while ago and can be found here (although since writing it, I've revamped the actual downloadable library):http://www.gutgames.com/page/HaterAide-ORM.aspxAs far as a "how to" app/section for using it, I'm going to be uploading a new updated version of it to CodePlex in the next week or so at http://hateraide.codeplex.com. I'll be including a test app in the documentation section there.

Qamar
July 07, 2010 7:27 AM

Hi, Sir you have done nice job. When you expect to complete this ORM model. Will you make a test application to show, how to use this ORM model. Thanks