none
TPH : Cannot set scalar property of a derived class to null RRS feed

  • Question

  • Hi there,

    I have the table structure and the entity model (using TPH) as show in the pictures.


    The problem that I'm facing is that I can't reset the [TeacherAliasName] back to null althought the EntityState == Modified. Besides that, the SubmitChanges() operation doesn't throw an exception or error.

    Any idea how to solve this issue?



    • Edited by ehor Thursday, January 23, 2014 7:11 AM Change screenshot
    Thursday, January 23, 2014 7:07 AM

All replies

  • Hello,

    >>The problem that I'm facing is that I can't reset the [TeacherAliasName] back to null althought the EntityState == Modified.

    How do you set the [TeacherAliasName] to be null? I made a simple which is similar with yours:

    The tables schema:

    In database, it is shown as below:

    CREATE TABLE [dbo].[BillingDetails] (
    
        [BillingDetailId] INT            NOT NULL,
    
        [Owner]           NVARCHAR (MAX) NULL,
    
        [Number]          NVARCHAR (MAX) NULL,
    
        [BankName]        NVARCHAR (MAX) NULL,
    
        [Swift]           NVARCHAR (MAX) NULL,
    
        [CardType]        INT            NULL,
    
        [ExpiryMonth]     NVARCHAR (MAX) NULL,
    
        [ExpiryYear]      NVARCHAR (MAX) NULL,
    
        [Discriminator]   NVARCHAR (128) NOT NULL,
    
        CONSTRAINT [PK_dbo.BillingDetails] PRIMARY KEY CLUSTERED ([BillingDetailId] ASC)
    
    );
    

    I use codes as below to set the BankName to be null:

      BankAccount bankAccount = db.BillingDetails.OfType<BankAccount>().FirstOrDefault();
    
    
                    bankAccount.BankName = null;
    
    
                    db.SaveChanges();
    

    And it is successful.

    You can have a try.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 23, 2014 10:27 AM
    Moderator
  • Yup. I'm having the same setup as yours.

    The only different is that I'm calling SubmitChanges as the it is RIA service and also my project is in Silverlight.

    Friday, January 24, 2014 8:10 AM
  • Hello,

    The "SubmitChanges" is used for LINQ2SQL, do you use Entity Framework or LINQ2SQL?

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 24, 2014 8:13 AM
    Moderator
  • Basically the SubmitChanges() is called from the client side after the loading. The code like below:

    ctx.Load(ctx.GetTeacherByIdQuery(12345), lo => {
    
    
    
    var teacher = lo.Entities.FirstOrDefault() as Teacher;
    
    teacher.TeacherAliasName = null;
    
    ctx.SubmitChanges()
    
    
    
    }


    Tuesday, January 28, 2014 11:15 PM
  • Hello,

    After it called SubmitChanges(), what is the value of TeacherAliasName property?

    Since we cannot reproduce it could you please upload a simple demo which can reproduce it to skydriverso that we can download it and then test it to see whether it cannot be saved back to database.

    Or you can post it to:

    http://social.msdn.microsoft.com/Forums/silverlight/en-us/home?category=silverlight

    There are more Silverlight experts  who will help you better.

    Regards.

    Wednesday, January 29, 2014 8:58 AM
    Moderator