简体   繁体   English

版本和序列化

[英]Versioning and Serialization

So this is a question about Serialization and Versioning. 因此,这是有关序列化和版本控制的问题。 I have a program that is a Music database that stores sheet music with Name, Composer, ... I serialize each song to a hidden folder so that the user can reload the database at next launch. 我有一个程序,它是一个音乐数据库,该数据库存储带有Name,Composer等的活页乐谱...我将每首歌曲序列化到一个隐藏的文件夹中,以便用户在下次启动时可以重新加载该数据库。

Now, when I have to change something in the Song class all is fine if it is a compatible change. 现在,当我必须更改Song类中的某些内容时,如果它是兼容的更改,那一切都很好。 I had the idea that if I were to make an incompatible change, would I be able to create a second class with the same name 'Song' but a different VersionUID. 我的想法是,如果要进行不兼容的更改,则可以创建第二个具有相同名称“ Song”但具有不同VersionUID的类。 Then when it reads the Songs, if the saved version doesn't match the latest version, it will go to a method that will read the Song into the old UID then go through a series of steps to convert it to the new Version. 然后,当它读取歌曲时,如果保存的版本与最新版本不匹配,它将转到一种将歌曲读取为旧UID的方法,然后执行一系列步骤将其转换为新版本。 Is any of this possible? 有可能吗?

I do know that you can have multiple methods with the same name but different parameters. 我确实知道您可以使用名称相同但参数不同的多个方法。 Would this work with classes and VersionUID's or some other variable? 这可以与类和VersionUID或其他变量一起使用吗?

Thanks! 谢谢!

No it would not. 不,它不会。 Classes do not support a concept like "property overload" so a class with the same name is considered as the same class, even if it has different properties. 类不支持“属性重载”之类的概念,因此,具有相同名称的类将被视为同一类,即使它具有不同的属性。

The "best" way for you would be a migration to a relational database in combination with EntityFramework6 (there is a SQLite adapter out there, so you don't need SQLServer). 对您而言,“最佳”方法是与EntityFramework6一起迁移到关系数据库(那里有一个SQLite适配器,因此您不需要SQLServer)。 With EF you can use migrations which enables you to change your model and migrate the data automatically. 借助EF,您可以使用迁移,该迁移使您可以更改模型并自动迁移数据。 If done correctly you can change the model and no data loss occurs. 如果操作正确,您可以更改模型,并且不会丢失数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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