Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1110091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:20:29+00:00 2026-05-17T02:20:29+00:00

If column allow does not allow NULL in db then a condition in setter

  • 0

If column allow does not allow NULL in db then a condition in setter of generated property in Entity Framework is if (_ColumnName != value)

What is the use of this?

Why this condition is missing in setter generated from columns which allow NULL?

[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String Address1
{
    get
    {
    return _Address1;
    }
    set
    {
    if (_Address1 != value) // This condition is only for columns which are not null in db. Why this is not needed for nullable columns.
    {
        OnAddress1Changing(value);
        ReportPropertyChanging("Address1");
        _Address1 = StructuralObject.SetValidValue(value, false);
        ReportPropertyChanged("Address1");
        OnAddress1Changed();
    }
    }
}
private global::System.String _Address1;

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String Address2
{
    get
    {
    return _Address2;
    }
    set
    {
        // NO IF CONDITION HERE LIKE IT IS IN PROPERTY WHICH DON'T ALLOW NULL (ABOVE PROPERTY ADDRESS1)
        OnAddress2Changing(value);
    ReportPropertyChanging("Address2");
    _Address2 = StructuralObject.SetValidValue(value, true);
    ReportPropertyChanged("Address2");
    OnAddress2Changed();
    }
}
private global::System.String _Address2;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:20:30+00:00Added an answer on May 17, 2026 at 2:20 am

    No, that if condition has nothing to do with whether or not the property is Nullable. It will be generated only when the property is EntityKey.

    Digging into the ADO.NET EntityObject Generator T4 templte (which is the default code generation tool and is the one that VS 2010 uses to generate Entity Objects) reveals this:

    if (ef.IsKey(primitiveProperty))
                {
                    if (ef.ClrType(primitiveProperty.TypeUsage) == typeof(byte[]))
                    {
    #>
                if (!StructuralObject.BinaryEquals(<#=code.FieldName(primitiveProperty)#>, value))
    <#+
                    }
                    else
                    {
    #>
                // Here it inject the if condition:
                if (<#=code.FieldName(primitiveProperty)#> != value )
    <#+
                    }
    #>
                {
    <#+
            PushIndent(CodeRegion.GetIndent(1));
                }
    #>
                <#=ChangingMethodName(primitiveProperty)#>(value);
                ReportPropertyChanging("<#=primitiveProperty.Name#>");
                <#=code.FieldName(primitiveProperty)#> = StructuralObject.SetValidValue(value<#=OptionalNullableParameterForSetValidValue(primitiveProperty, code)#>);
                ReportPropertyChanged("<#=primitiveProperty.Name#>");
                <#=ChangedMethodName(primitiveProperty)#>();
    <#+
            if (ef.IsKey(primitiveProperty))
                {
            PopIndent();
    #>
                }
    <#+
                }
    #>
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Cannot insert the value null into column 'COLUMN1',table'DB1.dbo.table1';Column does not allow nulls. Insert fails.the
I added a column to my table that does not allow null. I guess
I am getting java.sql.SQLException: The column ID in table METAL_HAREKET_IPTAL does not allow null
Hibernate does not allow me to persist an object that contains an null embedded
Why does Sql server doesn't allow more than one IDENTITY column in a table??
I use Entity Framework 4.1, SQL Server 2008 & .NET 4.0 I have a
Can I add a column which is I specify as NOT NULL,I don't want
Is it possible to allow a user to add and edit column names for
What column does DISTINCT work with in JPA and is it possible to change
I´m trying out entity framework included in VS2010 but ´ve hit a problem with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.