Beispiel #1
0
 public T CreateOrRetrieve <T>(ef.DbSet <T> set, Func <T, bool> create_predicate, Func <T, bool> retrieve_predicate, T obj = null, bool SaveOnCreate = true) where T : class, IHasIntId
 {
     if (obj.id == 0)
     {
         return(this.FirstOrCreate(set, create_predicate, obj, SaveOnCreate));
     }
     else
     {
         return(set.Single(retrieve_predicate));
     }
 }
Beispiel #2
0
        public T FirstOrCreate <T>(ef.DbSet <T> set, Func <T, bool> predicate, T obj = null, bool SaveOnCreate = true) where T : class
        {
            T result;

            try
            {
                result = set.First(predicate);
            }
            catch (InvalidOperationException)
            {
                set.Add(obj);
                if (SaveOnCreate)
                {
                    this.SaveChanges();
                }
                result = obj;
            }
            return(result);
        }
Beispiel #3
0
 public virtual T CreateOrRetrieve <T>(ef.DbSet <T> set, Func <T, bool> predicate, T obj = null, bool SaveOnCreate = true) where T : class, IHasIntId, IHasPartitionString
 {
     return(this.CreateOrRetrieve(set, predicate, (x) => x.id == obj.id && x.partition == obj.partition, obj, SaveOnCreate));
 }
Beispiel #4
0
 public T SingleOrCreate <T>(ef.DbSet <T> set, T obj = null, bool SaveOnCreate = false) where T : element
 {
     return(this.CreateOrRetrieve(set, x => x.gm_name == obj.gm_name && x.partition == obj.partition, obj, SaveOnCreate));
 }