简体   繁体   中英

data annotations entity framework

I have created this table:

    public string Name { get; set; }    
    public string Description { get; set; }
    [ForeignKey("CityId")]
    public City City { get; set; }
    public int CityId { get; set; }

Now I like to set CityId to null, and I Try this:

    public string Name { get; set; }    
    public string Description { get; set; }
    [ForeignKey("CityId")]
    public City City { get; set; }
    public int? CityId { get; set; }

But when I create the new migration in Package Manager Console (add-migration Curso_CityIdNullable), the migration generated is empty...

    public override void Up()
    {
    }

    public override void Down()
    {
    }

Any help?? Thanks

Your change doesn't set the CityId to null. It makes it nullable! That's not the same. What do you want, set a the field CityId in a row to null or set the field as nullable?

A list of data annotations for ef can you find here: http://www.entityframeworktutorial.net/code-first/dataannotation-in-code-first.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM