none
Have a bug in EF migration when using muti languages RRS feed

  • Question

  • In my project we use muti languages, so in one model it is defined as below:

    public class Person: Model
    {
    
    [StringLength(50, ErrorMessageResourceName = "FirstNameLong", ErrorMessageResourceType = typeof(Resources.Res))]
    
    [Display(Name = "FirstName", ResourceType = typeof(Resources.Res))]
    
    public string FirstName { get; set; }
    
    }


    Then I do 'add-migration update' in Package Manager Console 

    the migration file always have a change as below:

    public partial class Update : DbMigration
        {
            public override void Up()
            {
                AlterColumn("dbo.Person", "FirstName", c => c.String());
            }
            
            public override void Down()
            {
                AlterColumn("dbo.Person", "FirstName", c => c.String(maxLength: 50));
            }
        }

    If I delete the attributes, and defined the model as below:

    public class Person: Model
    {
    
    [StringLength(50)]
    public string FirstName{ get; set; }
    }

    then in migration file shows no change. 

    Could anyone help to fix this problem?

    Friday, March 7, 2014 1:54 AM

Answers

  • Hello,

    Sorry for being late.

    I download your uploaded projects, however, I cannot run it since it needs me to install the tool.

    I notice that you let the entities in a separate model, I am confused why you do that. I suggest you put the context and entities together and then to check whether it will recover the entity again.

    From your comparison, it seems that the ErrorMessageResourceType may have a side effect.

    Have a try to use the fluent API to specify the string length and then to check whether it will be changed again.

    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.

    • Marked as answer by YangJia Wednesday, March 19, 2014 1:48 AM
    Monday, March 17, 2014 8:57 AM
    Moderator

All replies

  • Hello,

    >>Could anyone help to fix this problem?

    I made an example which is similar with yours, however, it worked fine. This deference is that since I do not how you define the Resource.Res, I remove it.

    My program is: a console application using EF6 with VS2013 and .NET Framework 4.5.

    Have a try to remove the Resource.Res to check whether it will work fine.

    If this does not work for you, could you please upload a small demo to:

    https://skydrive.live.com

    We can then download it.

    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.

    Saturday, March 8, 2014 8:29 AM
    Moderator
  • Thank you, I've uploaded it.

    https://onedrive.live.com/redir?resid=95BA11CB38DF5DB3!2664&authkey=!APGW_N5wmC9zb6U&ithint=file%2c.zip


    !

    Monday, March 10, 2014 6:13 AM
  • Hello,

    I am sorry that the file is too big and I cannot download it, if it is possible, could you please just give a small demo which can reproduce this issue.

    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.

    Monday, March 10, 2014 9:57 AM
    Moderator
  • I've uploaded a smaller one.

    https://onedrive.live.com/redir?resid=95BA11CB38DF5DB3%212665


    !

    Tuesday, March 11, 2014 2:34 AM
  • Hello,

    Sorry for being late.

    I download your uploaded projects, however, I cannot run it since it needs me to install the tool.

    I notice that you let the entities in a separate model, I am confused why you do that. I suggest you put the context and entities together and then to check whether it will recover the entity again.

    From your comparison, it seems that the ErrorMessageResourceType may have a side effect.

    Have a try to use the fluent API to specify the string length and then to check whether it will be changed again.

    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.

    • Marked as answer by YangJia Wednesday, March 19, 2014 1:48 AM
    Monday, March 17, 2014 8:57 AM
    Moderator
  • Thank you, I'll try.

    !

    Monday, March 17, 2014 9:18 AM
  • It is Ok to use the fluent API. Thank you.

    !

    Wednesday, March 19, 2014 1:48 AM