System.ComponentModel.DataAnnotations.Schema.ColumnAttribute inconsistent?












1














I seem to have run into a problem with the ColumnAttribute not working as expected.

Now i just want to point out that i have found a solution to my problem by simply using the AS keyword for naming the columns according to the C# properties, but that does not explain what happens to the ColumnAttribute.
As you can see in my SQL i applied the AS keyword to translate the column name, but i left some out to show the issue.



Heres the SQL query



var model = adsic.Database.SqlQuery<ADUser>(@"
SELECT
[mail],
[title] AS Title,
[c] AS Country,
[department] AS Department,
[company] AS Company,
[mobile],
[telephoneNumber],
[facsimileTelephoneNumber],
[name] AS Name,
[sAMAccountName] AS Username,
[l] AS Location,
[wWWHomePage] AS WebSite,
[manager] AS Manager
FROM openquery
(ADSI,'SELECT
mail, title, c, department, company,
mobile, telephoneNumber, facsimileTelephoneNumber, name, sAMAccountName,
l, wWWHomePage, manager
FROM ''LDAP://OU=Plus Pack,DC=global,DC=ns''
WHERE objectClass = ''User'' AND objectCategory = ''person'' '
)").AsQueryable().ToList();


If i run this directly on the SQL server everything looks fine and i get all fields populated
SQL output



The C# model that reflects the query



using System.ComponentModel.DataAnnotations.Schema;
public class ADUser
{
//[Key]
//[Column("distinguishedName")]
//public string DistinguishedName { get; set; }

[Column("mail")]
public string Mail { get; set; }

//[Column("title")]
public string Title { get; set; }

[Column("c")]
public string Country { get; set; }

//[Column("department")]
public string Department { get; set; }

//[Column("company")]
public string Company { get; set; }

[Column("mobile")]
public string MobileNumber { get; set; }

[Column("telephoneNumber")]
public string TelephoneNumber { get; set; }

[Column("facsimileTelephoneNumber")]
public string DepartmentNumber { get; set; }

//[Column("sAMAccountName")]
public string Username { get; set; }

//[Column("l")]
public string Location { get; set; }

//[Column("wWWHomePage")]
public string WebSite { get; set; }

//[Column("manager")]
public string Manager { get; set; }

//[Column("cn")]
public string Name { get; set; }
}


Now for the sketchy part. I debug the result after model translation in C#.
C# debug session
As you can see MobileNumber and DepartmentNumber do not get populated, despite both having a value in the raw SQL above. Whats more is that the other columns with ColumnAttribute Mail, Country, TelephoneNumber work just fine. I already tried several times to check for typos or hidden whitespace characters. If i dont use the ColumnAttribute at all and just use AS keyword for name translation i get all fields populated.










share|improve this question



























    1














    I seem to have run into a problem with the ColumnAttribute not working as expected.

    Now i just want to point out that i have found a solution to my problem by simply using the AS keyword for naming the columns according to the C# properties, but that does not explain what happens to the ColumnAttribute.
    As you can see in my SQL i applied the AS keyword to translate the column name, but i left some out to show the issue.



    Heres the SQL query



    var model = adsic.Database.SqlQuery<ADUser>(@"
    SELECT
    [mail],
    [title] AS Title,
    [c] AS Country,
    [department] AS Department,
    [company] AS Company,
    [mobile],
    [telephoneNumber],
    [facsimileTelephoneNumber],
    [name] AS Name,
    [sAMAccountName] AS Username,
    [l] AS Location,
    [wWWHomePage] AS WebSite,
    [manager] AS Manager
    FROM openquery
    (ADSI,'SELECT
    mail, title, c, department, company,
    mobile, telephoneNumber, facsimileTelephoneNumber, name, sAMAccountName,
    l, wWWHomePage, manager
    FROM ''LDAP://OU=Plus Pack,DC=global,DC=ns''
    WHERE objectClass = ''User'' AND objectCategory = ''person'' '
    )").AsQueryable().ToList();


    If i run this directly on the SQL server everything looks fine and i get all fields populated
    SQL output



    The C# model that reflects the query



    using System.ComponentModel.DataAnnotations.Schema;
    public class ADUser
    {
    //[Key]
    //[Column("distinguishedName")]
    //public string DistinguishedName { get; set; }

    [Column("mail")]
    public string Mail { get; set; }

    //[Column("title")]
    public string Title { get; set; }

    [Column("c")]
    public string Country { get; set; }

    //[Column("department")]
    public string Department { get; set; }

    //[Column("company")]
    public string Company { get; set; }

    [Column("mobile")]
    public string MobileNumber { get; set; }

    [Column("telephoneNumber")]
    public string TelephoneNumber { get; set; }

    [Column("facsimileTelephoneNumber")]
    public string DepartmentNumber { get; set; }

    //[Column("sAMAccountName")]
    public string Username { get; set; }

    //[Column("l")]
    public string Location { get; set; }

    //[Column("wWWHomePage")]
    public string WebSite { get; set; }

    //[Column("manager")]
    public string Manager { get; set; }

    //[Column("cn")]
    public string Name { get; set; }
    }


    Now for the sketchy part. I debug the result after model translation in C#.
    C# debug session
    As you can see MobileNumber and DepartmentNumber do not get populated, despite both having a value in the raw SQL above. Whats more is that the other columns with ColumnAttribute Mail, Country, TelephoneNumber work just fine. I already tried several times to check for typos or hidden whitespace characters. If i dont use the ColumnAttribute at all and just use AS keyword for name translation i get all fields populated.










    share|improve this question

























      1












      1








      1







      I seem to have run into a problem with the ColumnAttribute not working as expected.

      Now i just want to point out that i have found a solution to my problem by simply using the AS keyword for naming the columns according to the C# properties, but that does not explain what happens to the ColumnAttribute.
      As you can see in my SQL i applied the AS keyword to translate the column name, but i left some out to show the issue.



      Heres the SQL query



      var model = adsic.Database.SqlQuery<ADUser>(@"
      SELECT
      [mail],
      [title] AS Title,
      [c] AS Country,
      [department] AS Department,
      [company] AS Company,
      [mobile],
      [telephoneNumber],
      [facsimileTelephoneNumber],
      [name] AS Name,
      [sAMAccountName] AS Username,
      [l] AS Location,
      [wWWHomePage] AS WebSite,
      [manager] AS Manager
      FROM openquery
      (ADSI,'SELECT
      mail, title, c, department, company,
      mobile, telephoneNumber, facsimileTelephoneNumber, name, sAMAccountName,
      l, wWWHomePage, manager
      FROM ''LDAP://OU=Plus Pack,DC=global,DC=ns''
      WHERE objectClass = ''User'' AND objectCategory = ''person'' '
      )").AsQueryable().ToList();


      If i run this directly on the SQL server everything looks fine and i get all fields populated
      SQL output



      The C# model that reflects the query



      using System.ComponentModel.DataAnnotations.Schema;
      public class ADUser
      {
      //[Key]
      //[Column("distinguishedName")]
      //public string DistinguishedName { get; set; }

      [Column("mail")]
      public string Mail { get; set; }

      //[Column("title")]
      public string Title { get; set; }

      [Column("c")]
      public string Country { get; set; }

      //[Column("department")]
      public string Department { get; set; }

      //[Column("company")]
      public string Company { get; set; }

      [Column("mobile")]
      public string MobileNumber { get; set; }

      [Column("telephoneNumber")]
      public string TelephoneNumber { get; set; }

      [Column("facsimileTelephoneNumber")]
      public string DepartmentNumber { get; set; }

      //[Column("sAMAccountName")]
      public string Username { get; set; }

      //[Column("l")]
      public string Location { get; set; }

      //[Column("wWWHomePage")]
      public string WebSite { get; set; }

      //[Column("manager")]
      public string Manager { get; set; }

      //[Column("cn")]
      public string Name { get; set; }
      }


      Now for the sketchy part. I debug the result after model translation in C#.
      C# debug session
      As you can see MobileNumber and DepartmentNumber do not get populated, despite both having a value in the raw SQL above. Whats more is that the other columns with ColumnAttribute Mail, Country, TelephoneNumber work just fine. I already tried several times to check for typos or hidden whitespace characters. If i dont use the ColumnAttribute at all and just use AS keyword for name translation i get all fields populated.










      share|improve this question













      I seem to have run into a problem with the ColumnAttribute not working as expected.

      Now i just want to point out that i have found a solution to my problem by simply using the AS keyword for naming the columns according to the C# properties, but that does not explain what happens to the ColumnAttribute.
      As you can see in my SQL i applied the AS keyword to translate the column name, but i left some out to show the issue.



      Heres the SQL query



      var model = adsic.Database.SqlQuery<ADUser>(@"
      SELECT
      [mail],
      [title] AS Title,
      [c] AS Country,
      [department] AS Department,
      [company] AS Company,
      [mobile],
      [telephoneNumber],
      [facsimileTelephoneNumber],
      [name] AS Name,
      [sAMAccountName] AS Username,
      [l] AS Location,
      [wWWHomePage] AS WebSite,
      [manager] AS Manager
      FROM openquery
      (ADSI,'SELECT
      mail, title, c, department, company,
      mobile, telephoneNumber, facsimileTelephoneNumber, name, sAMAccountName,
      l, wWWHomePage, manager
      FROM ''LDAP://OU=Plus Pack,DC=global,DC=ns''
      WHERE objectClass = ''User'' AND objectCategory = ''person'' '
      )").AsQueryable().ToList();


      If i run this directly on the SQL server everything looks fine and i get all fields populated
      SQL output



      The C# model that reflects the query



      using System.ComponentModel.DataAnnotations.Schema;
      public class ADUser
      {
      //[Key]
      //[Column("distinguishedName")]
      //public string DistinguishedName { get; set; }

      [Column("mail")]
      public string Mail { get; set; }

      //[Column("title")]
      public string Title { get; set; }

      [Column("c")]
      public string Country { get; set; }

      //[Column("department")]
      public string Department { get; set; }

      //[Column("company")]
      public string Company { get; set; }

      [Column("mobile")]
      public string MobileNumber { get; set; }

      [Column("telephoneNumber")]
      public string TelephoneNumber { get; set; }

      [Column("facsimileTelephoneNumber")]
      public string DepartmentNumber { get; set; }

      //[Column("sAMAccountName")]
      public string Username { get; set; }

      //[Column("l")]
      public string Location { get; set; }

      //[Column("wWWHomePage")]
      public string WebSite { get; set; }

      //[Column("manager")]
      public string Manager { get; set; }

      //[Column("cn")]
      public string Name { get; set; }
      }


      Now for the sketchy part. I debug the result after model translation in C#.
      C# debug session
      As you can see MobileNumber and DepartmentNumber do not get populated, despite both having a value in the raw SQL above. Whats more is that the other columns with ColumnAttribute Mail, Country, TelephoneNumber work just fine. I already tried several times to check for typos or hidden whitespace characters. If i dont use the ColumnAttribute at all and just use AS keyword for name translation i get all fields populated.







      c# entity-framework linq-to-sql attributes data-annotations






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 12:49









      LuqJensen

      165210




      165210
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Duplicate of this post
          I dont know why, i didnt find this when i searched for my issue before i posted. Or why it wasnt suggested when i was writing my post. Its a shame about that really.
          Still, the behaviour of EF respecting the attribute sometimes and other times not, is really odd.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375006%2fsystem-componentmodel-dataannotations-schema-columnattribute-inconsistent%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Duplicate of this post
            I dont know why, i didnt find this when i searched for my issue before i posted. Or why it wasnt suggested when i was writing my post. Its a shame about that really.
            Still, the behaviour of EF respecting the attribute sometimes and other times not, is really odd.






            share|improve this answer


























              1














              Duplicate of this post
              I dont know why, i didnt find this when i searched for my issue before i posted. Or why it wasnt suggested when i was writing my post. Its a shame about that really.
              Still, the behaviour of EF respecting the attribute sometimes and other times not, is really odd.






              share|improve this answer
























                1












                1








                1






                Duplicate of this post
                I dont know why, i didnt find this when i searched for my issue before i posted. Or why it wasnt suggested when i was writing my post. Its a shame about that really.
                Still, the behaviour of EF respecting the attribute sometimes and other times not, is really odd.






                share|improve this answer












                Duplicate of this post
                I dont know why, i didnt find this when i searched for my issue before i posted. Or why it wasnt suggested when i was writing my post. Its a shame about that really.
                Still, the behaviour of EF respecting the attribute sometimes and other times not, is really odd.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 19 '18 at 13:10









                LuqJensen

                165210




                165210






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375006%2fsystem-componentmodel-dataannotations-schema-columnattribute-inconsistent%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                    Npm cannot find a required file even through it is in the searched directory