private string CheckSavedItemsSnippet(UniqueMultiplePropertiesInfo info)
        {
            return string.Format(@"            {{
                const string sql = @""SELECT source.*
                    FROM {0}.{1} source
                    INNER JOIN (SELECT {2} FROM {0}.{1} GROUP BY {2} HAVING COUNT(*) > 1) doubles
                        ON {3}"";

                var nhSqlQuery = _executionContext.NHibernateSession.CreateSQLQuery(sql).AddEntity(typeof({0}.{1}));
                var invalidItems = nhSqlQuery.List<{0}.{1}>();

                IEnumerable<Guid> changesItems = inserted.Select(item => item.ID).Union(updated.Select(item => item.ID));
                var changesItemsSet = new HashSet<Guid>(changesItems);
                invalidItems = invalidItems.Where(invalidItem => changesItemsSet.Contains(invalidItem.ID)).ToList();

                if (invalidItems.Count() > 0)
                {{
                    string msg = ""It is not allowed to enter a duplicate record. A record with the same value ("" + {4} + "") already exists in the system: "";
                    var invalidItem = invalidItems.First();
                    msg += ""("" + {5} + "")."";
                    throw new Rhetos.UserException(msg);
                }}
            }}
            ",
            info.DataStructure.Module.Name,
            info.DataStructure.Name,
            ColumnListTag.Evaluate(info),
            ColumnJoinTag.Evaluate(info),
            PropertyListTag.Evaluate(info),
            PropertyValuesTag.Evaluate(info));
        }
        private string CheckSavedItemsSnippet(UniqueMultiplePropertiesInfo info)
        {
            return string.Format(@"            {{
                const string sql = @""SELECT source.*
                    FROM {6}.{7} source
                    INNER JOIN (SELECT {2} FROM {6}.{7} GROUP BY {2} HAVING COUNT(*) > 1) doubles
                        ON {3}"";

                var invalidItems = _executionContext.EntityFrameworkContext.Database.SqlQuery<{0}.{1}>(sql).ToList();

                IEnumerable<Guid> changesItems = inserted.Select(item => item.ID).Union(updated.Select(item => item.ID));
                var changesItemsSet = new HashSet<Guid>(changesItems);
                invalidItems = invalidItems.Where(invalidItem => changesItemsSet.Contains(invalidItem.ID)).ToList();
                
                if (invalidItems.Count() > 0)
                {{
                    string msg = ""It is not allowed to enter a duplicate record in {0}.{1}. A record with the same value already exists in the system: "";
                    var invalidItem = invalidItems.First();
                    msg += {4} + "" '"" + {5} + ""'."";
                    throw new Rhetos.UserException(msg);
                }}
            }}
",
            info.DataStructure.Module.Name,
            info.DataStructure.Name,
            ColumnListTag.Evaluate(info),
            ColumnJoinTag.Evaluate(info),
            PropertyListTag.Evaluate(info),
            PropertyValuesTag.Evaluate(info),
            ((IWritableOrmDataStructure)info.DataStructure).GetOrmSchema(),
            ((IWritableOrmDataStructure)info.DataStructure).GetOrmDatabaseObject());
        }
 public static bool IsSupported(UniqueMultiplePropertiesInfo info)
 {
     return !UniqueMultiplePropertiesInfo.SqlImplementation(info)
         && info is IWritableOrmDataStructure;
 }
Пример #4
0
 public static bool SqlImplementation(UniqueMultiplePropertiesInfo info)
 {
     return info.DataStructure is EntityInfo;
 }
 public static bool ImplementInObjectModel(UniqueMultiplePropertiesInfo info)
 {
     return !info.SqlImplementation() && info.DataStructure is IWritableOrmDataStructure;
 }