コード例 #1
0
        /// <summary>
        /// Maps the database readed data into a new instance.
        /// </summary>
        private static T MapData(DbDataReader reader)
        {
            T      instance;
            object value;

            try
            {
                // Create the new instance
                instance = (T)Activator.CreateInstance(typeof(T), new object[] { });

                // Add primary key
                ORMEntity <T> .ORMStructure.PrimaryKey.SetValue(instance, reader);

                // After object is identified, add it to the memory table
                ORMEntity <T> .AddInMemoryTable(((ORMIdentifiableEntity)instance).ID, instance);

                foreach (ORMEntityMember member in ORMEntity <T> .ORMStructure)
                {
                    value = null;

                    if (member.IsForeignField)
                    {
                        value = member.GetReaderValue(instance, reader);
                        member.SetValue(instance, value);
                    }
                    else if (member.IsForeignCollection)
                    {
                        value = ORMEntity <T> .GetORMForeignCollection(member, instance);

                        member.SetValue(instance, value);
                    }
                    else
                    {
                        member.SetValue(instance, reader);
                    }

                    if (member.Attribute.IsOneToOneProperty)
                    {
                        ORMEntity <T> .SetOneToOneProperty(member.Attribute.OneToOnePropertyName, value, instance);
                    }
                }

                return(instance);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                throw ex;
            }
        }