EF does not recognize new Properties





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















Last week I created my models for this project, but needed to update them this week. First my "Person" class only had a "Name" property and now it has a "Firstname" and a "Lastname" property. Now I get an exception about the "Name" property, which doesn't even exist anymore.



The DB is not being created either, which is most likely a subsequent error.



Class Person



abstract class Person
{
[Key]
public int Id { get; set; }

[MaxLength(100)]
public string Firstname { get; set; }

[MaxLength(100)]
public string Lastname { get; set; }

public int Age { get; set; }
}


Class Student



class Student : Person
{
public School School { get; set; }

public virtual ICollection<Order> Orders { get; set; } = new List<Order>();
}


Trying to add a Student



using (var ctx = new SchoolDbContext())
{
ctx.Persons.Add(new Student() {Firstname="Test" });
ctx.SaveChanges();
}


DBContext



class SchoolDbContext : DbContext
{
public SchoolDbContext() : base("SchoolDB")
{

}

public DbSet<Person> Persons { get; set; }
public DbSet<School> Schools { get; set; }
public DbSet<AArticle> Articles { get; set; }
public DbSet<APublisher> APublishers { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Subject> Subjects { get; set; }

}


The Exception



System.InvalidOperationException: "The property 'Name' is not a String or Byte array. Length can only be configured for String and Byte array properties."



I tried cleaning the solution, restarting VS, rebuilding and recleaning... Cannot drop the DB as no DB is created.



How do I inform the compiler that the "Name" property does not exist anymore, as he does not get it himself?










share|improve this question























  • Do tou have any migrations?

    – Aldert
    Nov 23 '18 at 21:11


















-1















Last week I created my models for this project, but needed to update them this week. First my "Person" class only had a "Name" property and now it has a "Firstname" and a "Lastname" property. Now I get an exception about the "Name" property, which doesn't even exist anymore.



The DB is not being created either, which is most likely a subsequent error.



Class Person



abstract class Person
{
[Key]
public int Id { get; set; }

[MaxLength(100)]
public string Firstname { get; set; }

[MaxLength(100)]
public string Lastname { get; set; }

public int Age { get; set; }
}


Class Student



class Student : Person
{
public School School { get; set; }

public virtual ICollection<Order> Orders { get; set; } = new List<Order>();
}


Trying to add a Student



using (var ctx = new SchoolDbContext())
{
ctx.Persons.Add(new Student() {Firstname="Test" });
ctx.SaveChanges();
}


DBContext



class SchoolDbContext : DbContext
{
public SchoolDbContext() : base("SchoolDB")
{

}

public DbSet<Person> Persons { get; set; }
public DbSet<School> Schools { get; set; }
public DbSet<AArticle> Articles { get; set; }
public DbSet<APublisher> APublishers { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Subject> Subjects { get; set; }

}


The Exception



System.InvalidOperationException: "The property 'Name' is not a String or Byte array. Length can only be configured for String and Byte array properties."



I tried cleaning the solution, restarting VS, rebuilding and recleaning... Cannot drop the DB as no DB is created.



How do I inform the compiler that the "Name" property does not exist anymore, as he does not get it himself?










share|improve this question























  • Do tou have any migrations?

    – Aldert
    Nov 23 '18 at 21:11














-1












-1








-1








Last week I created my models for this project, but needed to update them this week. First my "Person" class only had a "Name" property and now it has a "Firstname" and a "Lastname" property. Now I get an exception about the "Name" property, which doesn't even exist anymore.



The DB is not being created either, which is most likely a subsequent error.



Class Person



abstract class Person
{
[Key]
public int Id { get; set; }

[MaxLength(100)]
public string Firstname { get; set; }

[MaxLength(100)]
public string Lastname { get; set; }

public int Age { get; set; }
}


Class Student



class Student : Person
{
public School School { get; set; }

public virtual ICollection<Order> Orders { get; set; } = new List<Order>();
}


Trying to add a Student



using (var ctx = new SchoolDbContext())
{
ctx.Persons.Add(new Student() {Firstname="Test" });
ctx.SaveChanges();
}


DBContext



class SchoolDbContext : DbContext
{
public SchoolDbContext() : base("SchoolDB")
{

}

public DbSet<Person> Persons { get; set; }
public DbSet<School> Schools { get; set; }
public DbSet<AArticle> Articles { get; set; }
public DbSet<APublisher> APublishers { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Subject> Subjects { get; set; }

}


The Exception



System.InvalidOperationException: "The property 'Name' is not a String or Byte array. Length can only be configured for String and Byte array properties."



I tried cleaning the solution, restarting VS, rebuilding and recleaning... Cannot drop the DB as no DB is created.



How do I inform the compiler that the "Name" property does not exist anymore, as he does not get it himself?










share|improve this question














Last week I created my models for this project, but needed to update them this week. First my "Person" class only had a "Name" property and now it has a "Firstname" and a "Lastname" property. Now I get an exception about the "Name" property, which doesn't even exist anymore.



The DB is not being created either, which is most likely a subsequent error.



Class Person



abstract class Person
{
[Key]
public int Id { get; set; }

[MaxLength(100)]
public string Firstname { get; set; }

[MaxLength(100)]
public string Lastname { get; set; }

public int Age { get; set; }
}


Class Student



class Student : Person
{
public School School { get; set; }

public virtual ICollection<Order> Orders { get; set; } = new List<Order>();
}


Trying to add a Student



using (var ctx = new SchoolDbContext())
{
ctx.Persons.Add(new Student() {Firstname="Test" });
ctx.SaveChanges();
}


DBContext



class SchoolDbContext : DbContext
{
public SchoolDbContext() : base("SchoolDB")
{

}

public DbSet<Person> Persons { get; set; }
public DbSet<School> Schools { get; set; }
public DbSet<AArticle> Articles { get; set; }
public DbSet<APublisher> APublishers { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Subject> Subjects { get; set; }

}


The Exception



System.InvalidOperationException: "The property 'Name' is not a String or Byte array. Length can only be configured for String and Byte array properties."



I tried cleaning the solution, restarting VS, rebuilding and recleaning... Cannot drop the DB as no DB is created.



How do I inform the compiler that the "Name" property does not exist anymore, as he does not get it himself?







c# entity-framework model






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 19:13









MreifenbergerMreifenberger

104




104













  • Do tou have any migrations?

    – Aldert
    Nov 23 '18 at 21:11



















  • Do tou have any migrations?

    – Aldert
    Nov 23 '18 at 21:11

















Do tou have any migrations?

– Aldert
Nov 23 '18 at 21:11





Do tou have any migrations?

– Aldert
Nov 23 '18 at 21:11












1 Answer
1






active

oldest

votes


















0














You need to sync your database with your code by so-called migrations:
- ef core: https://docs.microsoft.com/de-de/ef/core/managing-schemas/migrations/
- ef 6: https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/






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%2f53451914%2fef-does-not-recognize-new-properties%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









    0














    You need to sync your database with your code by so-called migrations:
    - ef core: https://docs.microsoft.com/de-de/ef/core/managing-schemas/migrations/
    - ef 6: https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/






    share|improve this answer




























      0














      You need to sync your database with your code by so-called migrations:
      - ef core: https://docs.microsoft.com/de-de/ef/core/managing-schemas/migrations/
      - ef 6: https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/






      share|improve this answer


























        0












        0








        0







        You need to sync your database with your code by so-called migrations:
        - ef core: https://docs.microsoft.com/de-de/ef/core/managing-schemas/migrations/
        - ef 6: https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/






        share|improve this answer













        You need to sync your database with your code by so-called migrations:
        - ef core: https://docs.microsoft.com/de-de/ef/core/managing-schemas/migrations/
        - ef 6: https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 12:44









        GrimmGrimm

        211211




        211211
































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451914%2fef-does-not-recognize-new-properties%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







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()