open again: default value problem

2 posts, 0 answers
  1. Thomas
    Thomas  avatar
    18 posts
    Member since:
    Jun 2012

    Posted 04 Jun 2015 Link to this post

    hi i only found 

    this   http://www.telerik.com/forums/default-datetime-value-insert-error similar problem i had now the same.

     

    i want only insert new record in alookup table with attributes that should be filled on db side and not in UI. 

    the orm class includes e.g this  property  "modify_user" and in my  Model Schema Explorer the

    HasDefaultValue = True

    and also IsNullable = True

    are set.

    Property of Lookup class :

            private string _modify_user;
            [Column("modify_user", OpenAccessType = OpenAccessType.StringVariableLength, IsNullable = true, Length = 60, Scale = 0, SqlType = "'dom_name'")]
            [Storage("_modify_user")]
            [System.ComponentModel.DisplayName("")]
            [System.ComponentModel.DataAnnotations.StringLength(60)]
            public virtual string modify_user
            {
                get
                {
                    return this._modify_user;
                }
                set
                {
                    if(this._modify_user != value)
                    {
                        this.OnPropertyChanging("modify_user");
                        this._modify_user = value;
                        this.OnPropertyChanged("modify_user");
                    }
                }
            } 

     

    but my insert doen´t work correctly the ORM always raising

    sry in German , in English it´s Could not Enter null into modify_user.

    >>Telerik.OpenAccess Information: 49 : driver.stat.execUpdate      3 INSERT INTO [lookup] ([alias_id], [create_date], [create_user], [customized_flg], >>[description_txt], [display_nam], [display_short_txt], [external_uri], [lookup_lkp], [modify_date], [modify_user], [report_txt]) VALUES (@p0, @p1, @p2, @p3, >>@p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11)
    >>Telerik.OpenAccess Error: 49 : System.Data.SqlClient.SqlException: Der Wert NULL kann in die modify_user-Spalte, GapJunctionMaster.dbo.lookup-Tabelle >>nicht eingefügt werden. Die Spalte lässt NULL-Werte nicht zu. Fehler bei INSERT. Die Anweisung wurde beendet.

     

    and this is also the reason because the INSERT send to SQL Server is wrong. It includes the Columns that are set as HAsDefaultValue = true.

     

    Table

    CREATE TABLE [dbo].[lookup](
        [lookup_lkp] [dbo].[dom_lookup] NOT NULL,
        [alias_id] [dbo].[dom_identifier] NOT NULL,
        [external_uri] [dbo].[dom_uri] NOT NULL,
        [customized_flg] [dbo].[dom_flag] NULL,
        [display_nam] [dbo].[dom_name] NOT NULL,
        [display_short_txt] [dbo].[dom_displayname] NOT NULL,
        [report_txt] [dbo].[dom_reportname] NULL,
        [description_txt] [dbo].[dom_description] NULL,
        [create_user] [dbo].[dom_name] NOT NULL CONSTRAINT [df_lookup_create_user]  DEFAULT (suser_name()),
        [create_date] [dbo].[dom_begin_date] NOT NULL CONSTRAINT [df_lookup_create_date]  DEFAULT (getdate()),
        [modify_user] [dbo].[dom_name] NOT NULL CONSTRAINT [df_lookup_modify_user]  DEFAULT (suser_name()),
        [modify_date] [dbo].[dom_begin_date] NOT NULL CONSTRAINT [df_lookup_modify_date]  DEFAULT (getdate()),
     CONSTRAINT [PK_LOOKUP] PRIMARY KEY NONCLUSTERED
    (
        [lookup_lkp] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]

     

    in SQL Server this Insert is working

    INSERT INTO [dbo].[lookup]
               ([lookup_lkp]
               ,[alias_id]
               ,[external_uri]
               ,[customized_flg]
               ,[display_nam]
               ,[display_short_txt]
               ,[report_txt]
               ,[description_txt]
    )
         VALUES
               ('B%%%A'
               ,'E2350CD3-9607-1490-3575-EB0071D10789'
               ,'test'
               ,'t'
               ,'test'
               ,'test'
               ,'test'
               ,'test'
    )

    but this is not  working, and Telerik Data Access is sending all of the Columns

    INSERT INTO [dbo].[lookup]
               ([lookup_lkp]
               ,[alias_id]
               ,[external_uri]
               ,[customized_flg]
               ,[display_nam]
               ,[display_short_txt]
               ,[report_txt]
               ,[description_txt]
               ,[modify_user]
    )
         VALUES
               ('B%%%A'
               ,'E2350CD3-9607-1490-3575-EB0071D10789'
               ,'test'
               ,'t'
               ,'test'
               ,'test'
               ,'test'
               ,'test'
               ,null
    )
    GO

    So now the Question where is the flag i need to set that  the Insert is only without the Values (hasdefaultvalue = true) and are different then NULL send to SQL Server. ? 

    thnx br thomas 

     

     

     

     

     

     

     

     

  2. Thomas
    Thomas  avatar
    18 posts
    Member since:
    Jun 2012

    Posted 05 Jun 2015 in reply to Thomas Link to this post

    Found by my self.  Additionaly the Storage Behavior must be set to PersistantReadOnly. then the Insert is created only with those columns expected. And the server side Constraint ( SQL Server ) is executed.

     

     

  3. DevCraft banner
Back to Top