Commits

Mike Podonyi  committed d192773

some Work on RepositoryBase

  • Participants
  • Parent commits acfc510

Comments (0)

Files changed (2)

File src/Empi.Camino/Configuration/CaminoSettingsProvider.cs

                 }
                 else
                 {
-                    Empi.Camino.Data.IConfigurationBase propValue = retailerDataConfiguration.CreateInstance();
+                    Empi.Camino.Data.IConfigurationBase propValue = retailerDataConfiguration.CreateInstance((Type)context["ConfigurationTableType"]);
                     propValue.Key = settingsPropertyValue.Name;
                     propValue.Value = settingsPropertyValue.SerializedValue.ToString();
                 }

File src/Empi.Camino/Data/RepositoryBase.cs

 
         private IDataContextFactory dataContextFactory;
 
-        /// <summary>
-        /// Return all instances of type T.
-        /// </summary>
-        /// <returns></returns>
-        internal IQueryable<TEntity> All()
-        {
-            return GetTable();
-        }
+        ///// <summary>
+        ///// Return all instances of type T.
+        ///// </summary>
+        ///// <returns></returns>
+        //internal IQueryable<TEntity> All()
+        //{
+        //    return GetTable();
+        //}
 
-        /// <summary>
-        /// Return all instances of type T that match the expression exp.
-        /// </summary>
-        /// <param name="exp"></param>
-        /// <returns></returns>
-        internal IEnumerable<TEntity> FindAll(Expression<Func<TEntity, bool>> exp)
-        {
-            return GetTable().Where<TEntity>(exp);
-        }
+        ///// <summary>
+        ///// Return all instances of type T that match the expression exp.
+        ///// </summary>
+        ///// <param name="exp"></param>
+        ///// <returns></returns>
+        //internal IEnumerable<TEntity> FindAll(Expression<Func<TEntity, bool>> exp)
+        //{
+        //    return GetTable().Where<TEntity>(exp);
+        //}
 
         internal TEntity Single(Expression<Func<TEntity, bool>> exp)
         {
             return GetTable().Single(exp);
         }
 
-        internal TEntity Single(Expression<Func<TEntity, bool>> exp, Type type)
+        //internal TEntity Single(Expression<Func<TEntity, bool>> exp, Type type)
+        //{
+        //    return GetTable(type).Single(exp);
+        //}
+
+        internal TEntity SingleOrDefault(Expression<Func<TEntity, bool>> exp, Type type)
         {
-            return GetTable(type).Single(exp);
+            return GetTable(type).OfType<TEntity>().SingleOrDefault(exp); //MP: cast or oftype, not sure, test it
         }
 
         internal TEntity First(Expression<Func<TEntity, bool>> exp)
             return GetTable().First(exp);
         }
 
-        internal TEntity First(Expression<Func<TEntity, bool>> exp, Type type)
-        {
-            return GetTable(type).First(exp);
-        }
+        
 
-        internal virtual void MarkForDeletion(TEntity entity)
-        {
-            GetTable().DeleteOnSubmit(entity);
-        }
+        //internal TEntity First(Expression<Func<TEntity, bool>> exp, Type type)
+        //{
+        //    return GetTable(type).First(exp);
+        //}
+
+        //internal virtual void MarkForDeletion(TEntity entity)
+        //{
+        //    GetTable().DeleteOnSubmit(entity);
+        //}
 
         /// <summary>
         /// Create a new instance of type T.
         /// </summary>
         /// <returns></returns>
-        internal virtual TEntity CreateInstance()
+        //internal virtual TEntity CreateInstance()
+        //{
+        //    TEntity entity = Activator.CreateInstance<TEntity>();
+        //    GetTable().InsertOnSubmit(entity);
+        //    return entity;
+        //}
+
+        internal virtual TEntity CreateInstance(Type type)
         {
-            TEntity entity = Activator.CreateInstance<TEntity>();
+            TEntity entity = (TEntity) Activator.CreateInstance(type);
             GetTable().InsertOnSubmit(entity);
             return entity;
         }
             return dataContextFactory.DataContext.GetTable<TEntity>();
         }
 
-        private Table<TEntity> GetTable(Type type)
+        // give here back an ITable because Executiontime should be the latest possible 
+        // if you make a cast  or oftype its getting executed
+        private ITable GetTable(Type type) 
         {
-             return ((Table<TEntity>) dataContextFactory.DataContext.GetTable(type)); 
+            return dataContextFactory.DataContext.GetTable(type); 
         }
 
         private System.Data.Linq.Mapping.MetaTable TableMetadata