locked
Validation error: This property can not be set to a null value [updated with test case!] RRS feed

  • Question

  • User1346026359 posted
    Hi,

    In a dynamic data web application, I get a validation error on a non-null nvarchar(50) column in ListDetails.aspx, even though I have entered a value which should be accepted. The validation error is: "This property cannot be set to a null value.".

    I can not reproduce this on northwind/adventureworks.

    Any ideas?

    UPDATE: I have created a complete test case: http://printf.no/DynamicDataBugTest.zip (The archive was scanned with the latest AVG definitions before uploading to my private secure dedicated FreeBSD server)

    The test case contains:
    • One Dynamic Data Web App project
    • One MS SQL Server 2005 database backup which contains a single table with three columns
    • One screenshot showing how the error manifests itself


    I am fairly convinced now that this is a reproducible DD bug.

    -Andreas
    Thursday, March 5, 2009 8:26 AM

Answers

  • User-330204900 posted

    Hi Andreas, I found what was wrong initially I got the same error on my system as yours but I noticed that even when I made a change to the Global.asax.cs file this was not relected in the running website so I deleted the contents of the bin and obj folders (usually hidden just click the "Show All Files" button) recompiled and all was fine the error was gone. All I can think of it's some setting on your copy of VS not recompiling the website because once I had deleted the comipled files I can make changes and rerun and the changes now are there straight away.

     

    Hope this helps [:D]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 10, 2009 6:10 AM

All replies

  • User-330204900 posted

    Can you post the schema of the table in question? And is the error shown as a DD Validation error or a Yellow screnn?

    Thursday, March 5, 2009 8:54 AM
  • User1346026359 posted
    It's a DD validation error message. Red, scary text :) I need to correct my initial post though -- the problematic columns are indeed nullable! Here's the basic schema:
    CREATE TABLE [dbo].[Member](
    	[Id] [int] IDENTITY(1,1) NOT NULL,
    	[RoleId] [int] NOT NULL,
    	[CommitteeId] [int] NOT NULL,
    	[ViceForId] [int] NULL,
    	[FirstName] [nvarchar](50) NOT NULL,
    	[LastName] [nvarchar](50) NOT NULL,
    	[Title] [nvarchar](50) NULL,
    	[StreetAddress] [nvarchar](50) NULL,
    	[PostalNumber] [nvarchar](20) NULL,
    	[PostalAddress] [nvarchar](50) NULL,
    	[WorkPhone] [nvarchar](20) NULL,
    	[WorkMobile] [nvarchar](20) NULL,
    	[HomePhone] [nvarchar](20) NULL,
    	[HomeMobile] [nvarchar](20) NULL,
    	[Email] [nvarchar](255) NULL,
    	[StartDate] [datetime] NULL,
    	[EndDate] [datetime] NULL,
    
    I also do a model update + recompile whenever I make changes to my database.
    Thursday, March 5, 2009 9:01 AM
  • User1346026359 posted
    Another relevant tidbit is that this only happens in rows when the current value is an empty string (example: StreetAddress). For any row where the string is non-empty, it works fine.
    Thursday, March 5, 2009 9:05 AM
  • User-330204900 posted

    Is it the StreetAddress that is the column or is it any column that causes the error?

    Thursday, March 5, 2009 9:36 AM
  • User-330204900 posted

    CREATE TABLE [dbo].[Member]( [Id] [int] IDENTITY(1,1) NOT NULL, [RoleId] [int] NOT NULL, [CommitteeId] [int] NOT NULL, [ViceForId] [int] NULL, [FirstName] [nvarchar](50) NOT NULL, [LastName] [nvarchar](50) NOT NULL, [Title] [nvarchar](50) NULL, [StreetAddress] [nvarchar](50) NULL, [PostalNumber] [nvarchar](20) NULL, [PostalAddress] [nvarchar](50) NULL, [WorkPhone] [nvarchar](20) NULL, [WorkMobile] [nvarchar](20) NULL, [HomePhone] [nvarchar](20) NULL, [HomeMobile] [nvarchar](20) NULL, Email [nvarchar](255) NULL, [StartDate] [datetime] NULL, [EndDate] [datetime] NULL,

    Is this from right clicking the table and going:

    If not could you do that and paste as I can't see a PK or any constraints. [:D]

    Thursday, March 5, 2009 9:50 AM
  • User1346026359 posted
    The error can happen for any of the nullable nvarchar columns if the corresponding value in a row is an empty string. Here's the complete script:
    /****** Object:  Table [dbo].[Member]    Script Date: 03/05/2009 16:05:51 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Member](
    	[Id] [int] IDENTITY(1,1) NOT NULL,
    	[RoleId] [int] NOT NULL,
    	[CommitteeId] [int] NOT NULL,
    	[ViceForId] [int] NULL,
    	[FirstName] [nvarchar](50) NOT NULL,
    	[LastName] [nvarchar](50) NOT NULL,
    	[Title] [nvarchar](50) NULL,
    	[StreetAddress] [nvarchar](50) NULL,
    	[PostalNumber] [nvarchar](20) NULL,
    	[PostalAddress] [nvarchar](50) NULL,
    	[WorkPhone] [nvarchar](20) NULL,
    	[WorkMobile] [nvarchar](20) NULL,
    	[HomePhone] [nvarchar](20) NULL,
    	[HomeMobile] [nvarchar](20) NULL,
    	[Email] [nvarchar](255) NULL,
    	[StartDate] [datetime] NULL,
    	[EndDate] [datetime] NULL,
     CONSTRAINT [PK_Member] PRIMARY KEY CLUSTERED 
    (
    	[Id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    
    GO
    ALTER TABLE [dbo].[Member]  WITH CHECK ADD  CONSTRAINT [FK_Member_Committee] FOREIGN KEY([CommitteeId])
    REFERENCES [dbo].[Committee] ([Id])
    GO
    ALTER TABLE [dbo].[Member] CHECK CONSTRAINT [FK_Member_Committee]
    GO
    ALTER TABLE [dbo].[Member]  WITH NOCHECK ADD  CONSTRAINT [FK_Member_Member_Vice] FOREIGN KEY([ViceForId])
    REFERENCES [dbo].[Member] ([Id])
    GO
    ALTER TABLE [dbo].[Member] NOCHECK CONSTRAINT [FK_Member_Member_Vice]
    GO
    ALTER TABLE [dbo].[Member]  WITH CHECK ADD  CONSTRAINT [FK_Member_Role] FOREIGN KEY([RoleId])
    REFERENCES [dbo].[Role] ([Id])
    GO
    ALTER TABLE [dbo].[Member] CHECK CONSTRAINT [FK_Member_Role]
    
    Thursday, March 5, 2009 10:06 AM
  • User-1005219520 posted

    >>I can not reproduce this on northwind/adventureworks.

    1. Create a new Dynamic Data project and import just one table so you can reproduce the error.
    2. Create a new Dynamic Data project and import just one table from NW or AdventureWorksLT that has the same data type. You might need to change a type so they match exactly. If you can repro with NW/LT, problem solved.
    3. Reduce complexity of your app
    4. Add complexity of NW app

    Repeat steps 3&4 until they converge, ie, you either find the bug or reproduce with NW. Report back your findings.

    Friday, March 6, 2009 12:47 PM
  • User1346026359 posted
    No luck so far.

    However, I have created a complete test case: http://printf.no/DynamicDataBugTest.zip (The archive was scanned with the latest AVG definitions before uploading to my private secure dedicated FreeBSD server)

    The test case contains:
    • One Dynamic Data Web App project
    • One MS SQL Server 2005 database backup which contains a single table with three columns
    • One screenshot showing how the error manifests itself


    I am fairly convinced now that this is a reproducible DD bug.

    -Andreas
    Tuesday, March 10, 2009 5:23 AM
  • User-330204900 posted

    Hi Andreas, I found what was wrong initially I got the same error on my system as yours but I noticed that even when I made a change to the Global.asax.cs file this was not relected in the running website so I deleted the contents of the bin and obj folders (usually hidden just click the "Show All Files" button) recompiled and all was fine the error was gone. All I can think of it's some setting on your copy of VS not recompiling the website because once I had deleted the comipled files I can make changes and rerun and the changes now are there straight away.

     

    Hope this helps [:D]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 10, 2009 6:10 AM
  • User1346026359 posted
    Did you run my test case? I deleted obj and bin and recompiled, still the same error.

    Thanks,
    Andreas
    Thursday, March 12, 2009 5:17 AM
  • User-330204900 posted

    Hi Andreas, Yes I ran your project with your DB restored got exactly the same error deleted both the contents of the obj and bin directories and the error went away, there must be something wroing with your PC do you want me to e-mail you the recompiled version with out the error to see if that works on your system [:D]

    Thursday, March 12, 2009 5:52 AM
  • User1346026359 posted
    Just to be sure: the first row contains a name which is an empty string? And you are now able to update that row? (see screenshot) Please provide a link to the compiled app and I will take a look. Thanks!
    Thursday, March 12, 2009 9:33 AM
  • User1826226228 posted

    I'm also having this problem. I created a new column called ReferralCode nvarchar(255) NOT NULL, updated my Model, compiled and I get this error. When debugging, I could noticed that the value is being correctly passed to the dictionary on the Text_Edit.ascx.cs:

    protected override void ExtractValues(IOrderedDictionary dictionary)
    {
        dictionary[Column.Name] = ConvertEditedValue(TextBox1.Text);
    }


    The dictionary contais the correct value, but then on the Model.Designer.cs when this value is passed to the Property, it is null:

    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.String ReferralCode
    {
        get
        {
            return _ReferralCode;
        }
        set
        {
            OnReferralCodeChanging(value); // here valus comes NULL
            ReportPropertyChanging("ReferralCode");
            _ReferralCode = StructuralObject.SetValidValue(value, false);
            ReportPropertyChanged("ReferralCode");
            OnReferralCodeChanged();
        }
    }


    Note that it doesn't happen with columns with the same characteristics, which I already had previously in the table. It only happens to new columns that I created now.

    Wednesday, September 8, 2010 11:17 AM
  • User-330204900 posted

    Hi Fabio, I would quickly build a test project and build the model afresh to see if the issue goes away, you do sometimes get issues with Linq to SQL or EF when updating the model, I offten just rebuild it from scratch.

    Friday, September 17, 2010 4:08 PM
  • User948706901 posted

    set default value of field property in your table

    http://picasaweb.google.com/114567200217602090959/TQqBxB?authkey=Gv1sRgCMC_1vDPg626vgE#5568607731164884402




    Tuesday, February 1, 2011 1:43 AM
  • User-330204900 posted

    Imaes missing please repost. 

    Tuesday, February 1, 2011 11:48 AM