Beispiel #1
0
        public static AccessType GetAuthorizationAccessType(this EntityCommandKind commandKind)
        {
            switch (commandKind)
            {
            case EntityCommandKind.SelectAll:
            case EntityCommandKind.SelectAllPaged:
            case EntityCommandKind.SelectByKey:
            case EntityCommandKind.SelectByKeyManyToMany:
            case EntityCommandKind.SelectByKeyArray:
            case EntityCommandKind.CustomSelect:
                return(AccessType.Peek);

            case EntityCommandKind.Update:
            case EntityCommandKind.CustomUpdate:
            case EntityCommandKind.PartialUpdate:
                return(AccessType.Update);

            case EntityCommandKind.Insert:
            case EntityCommandKind.CustomInsert:
                return(AccessType.Create);

            case EntityCommandKind.Delete:
            case EntityCommandKind.CustomDelete:
                return(AccessType.Delete);

            default:
                return(AccessType.None);
            }
        }//method
        private EntityCommand AddCommand(string commandName, string description, EntityCommandKind kind, EntityInfo entity, EntityKeyInfo selectKey = null)
        {
            var command = new EntityCommand(commandName, description, kind, entity, selectKey);

            _model.AddCommand(command);
            return(command);
        }
Beispiel #3
0
 public EntityCommand(string commandName, string description, EntityCommandKind kind, EntityInfo entity, EntityKeyInfo selectKey = null)
     : this(commandName, description, kind)
 {
     TargetEntityInfo = entity;
       Area = entity.Area;
       TargetEntityType = entity.EntityType;
       SelectKey = selectKey;
 }
        public static bool IsSelect(this EntityCommandKind kind)
        {
            switch (kind)
            {
            case EntityCommandKind.SelectAll:
            case EntityCommandKind.SelectAllPaged:
            case EntityCommandKind.SelectByKey:
            case EntityCommandKind.SelectByKeyManyToMany:
                return(true);

            default:
                return(false);
            }
        }
Beispiel #5
0
        public DbCommandInfo(EntityCommand entityCommand, string commandName, DbTableInfo table, DbExecutionType executionType, string sql, string tag)
            : base(table.DbModel, table.Schema, DbObjectType.Command, entityCommand)
        {
            EntityCommand  = entityCommand;
            CommandName    = commandName;
            Table          = table;
            ExecutionType  = executionType;
            Sql            = sql;
            Description    = EntityCommand.Description;
            DescriptiveTag = tag;
            //derived entities
            FullCommandName = Table.DbModel.Driver.FormatFullName(Schema, CommandName);
            Kind            = entityCommand.Kind;
            var dbModel = table.DbModel;

            dbModel.AddCommand(this);
            if (Table != null)
            {
                Table.CrudCommands.Add(this);
            }
            base.GlobalName = DbModelHelper.GetGlobalName(Schema, commandName);
        }
Beispiel #6
0
 public DbCommandInfo(EntityCommand entityCommand, string commandName, DbTableInfo table, DbExecutionType executionType, string sql, string tag)
     : base(table.DbModel, table.Schema, DbObjectType.Command, entityCommand)
 {
     EntityCommand = entityCommand;
       CommandName = commandName;
       Table = table;
       ExecutionType = executionType;
       Sql = sql;
       Description = EntityCommand.Description;
       DescriptiveTag = tag;
       //derived entities
       FullCommandName = Table.DbModel.Driver.GetFullName(Schema, CommandName);
       Kind = entityCommand.Kind;
       var dbModel = table.DbModel;
       dbModel.AddCommand(this);
       if(Table != null)
     Table.CrudCommands.Add(this);
       base.GlobalName = DbModelHelper.GetGlobalName(Schema, commandName);
 }
Beispiel #7
0
        //creates a TSQL statement that raises error with custom message like 'VITA:Concurrency/Update/books.Author/123' (123 is primary key value)
        private string BuildRowCountCheckStatement(DbTableInfo table, List <DbParamInfo> pkParams, EntityCommandKind commandKind)
        {
            const string sqlCheckRowCount = @"
IF @@RowCount = 0
BEGIN
  DECLARE @msg NVARCHAR(200) = {0};
  RAISERROR(@msg, 11, 111);
END
";
            //Build message expression
            var opType  = commandKind == EntityCommandKind.Update ? "Update" : "Delete";
            var msg     = "'" + ErrorTagConcurrentUpdateConflict + "/" + opType + "/" + table.FullName + "/' + ";
            var pkExprs = pkParams.Select(p => string.Format("CAST({0} AS NVARCHAR(50))", p.Name));
            var strPks  = string.Join(" + ';' + ", pkExprs);

            msg += strPks;
            var result = string.Format(sqlCheckRowCount, msg);

            return(result);
        }
Beispiel #8
0
 //creates a TSQL statement that raises error with custom message like 'VITA:Concurrency/Update/books.Author/123' (123 is primary key value)
 private string BuildRowCountCheckStatement(DbTableInfo table, List<DbParamInfo> pkParams, EntityCommandKind commandKind)
 {
     const string sqlCheckRowCount = @"
     IF @@RowCount = 0
     BEGIN
       DECLARE @msg NVARCHAR(200) = {0};
       RAISERROR(@msg, 11, 111);
     END
     ";
       //Build message expression
       var opType = commandKind == EntityCommandKind.Update ? "Update" : "Delete";
       var msg = "'" + ErrorTagConcurrentUpdateConflict + "/" + opType + "/" + table.FullName + "/' + ";
       var pkExprs = pkParams.Select(p => string.Format("CAST({0} AS NVARCHAR(50))", p.Name));
       var strPks = string.Join(" + ';' + ", pkExprs);
       msg += strPks;
       var result = string.Format(sqlCheckRowCount, msg);
       return result;
 }
Beispiel #9
0
 private EntityCommand AddCommand(string commandName, string description, EntityCommandKind kind, EntityInfo entity, EntityKeyInfo selectKey = null)
 {
     var command = new EntityCommand(commandName, description, kind, entity, selectKey);
       _model.AddCommand(command);
       return command;
 }
Beispiel #10
0
 private EntityCommand(string commandName, string description, EntityCommandKind kind)
 {
     CommandName = commandName;
       Description = description;
       Kind = kind;
       AccessType = Kind.GetAuthorizationAccessType();
       switch (Kind) {
     case EntityCommandKind.SelectAll: case EntityCommandKind.SelectAllPaged:
     case EntityCommandKind.SelectByKey:   case EntityCommandKind.SelectByKeyManyToMany:
     case EntityCommandKind.SelectByKeyArray:
       Flags |= EntityCommandFlags.IsQuery;
       break;
     case EntityCommandKind.CustomSelect:
       Flags |= EntityCommandFlags.IsQuery | EntityCommandFlags.IsCustom;
       break;
     case EntityCommandKind.CustomInsert: case EntityCommandKind.CustomUpdate: case EntityCommandKind.CustomDelete:
       Flags |= EntityCommandFlags.IsCustom;
       break;
       }
 }
Beispiel #11
0
        public List<string> UpdateMemberNames; //For PartialUpdate - names of members to update

        #endregion Fields

        #region Constructors

        public EntityCommand(string commandName, string description, EntityCommandKind kind, Type entityType, EntityArea area)
            : this(commandName, description, kind)
        {
            TargetEntityType = entityType;
              Area = area;
        }