简体   繁体   English

将电影对象保存在其他文件中并将它们与实际收藏夹中的电影对象相关联的最佳方法是什么?

[英]What's the best way to save movie objects inside other files and associate them with the ones in the actual collection?

I have a collection of Movie objects in a HashSet<Movie> . 我在HashSet<Movie>有一个Movie对象的集合。 Movie type has properties such has Name , Year , Length , Genre , etc. 电影类型具有诸如NameYearLengthGenre等的属性。

I also has user profiles stored in individual files. 我还将用户个人资料存储在单个文件中。 I want to have each user to have a number of favorite movies. 我想让每个用户都有一些喜欢的电影。

But I am not sure how to "connect"/reference these movies inside the user profiles. 但是我不确定如何在用户配置文件中“连接” /引用这些电影。

Should I just rely on names? 我应该只依靠名字吗?

What's the best way to store the favorite movies in these individual user profiles? 在这些用户个人资料中存储喜欢的电影的最佳方法是什么? I can't think of any other than using names, but this feels like a fragile way. 除了使用名称之外,我别无其他,但这听起来像是一种脆弱的方式。 Also movie names are not unique. 电影名称也不是唯一的。 There are some with the same names. 有一些同名。

Any ideas? 有任何想法吗?

If you are hoping to link your Movie objects to another object, that I'm assuming are saved out for persistence, then you'd probably want to have some sort of unique identifier ( Guid probably) that is associated with the Movie class. 如果您希望将Movie对象链接到另一个对象,而我假设这些对象将被保存以保持持久性,那么您可能希望具有与Movie类相关联的某种唯一标识符(可能是Guid )。

The User class would then have a list of Guid s that represent the movies connected as favorites (or you can preload this with the actual movie objects) 然后, User类将具有一个Guid列表,这些列表代表作为收藏夹连接的电影(或者您可以将其实际加载为电影对象)

I don't know if the below approach is the best, but have you considered generating a hash value from the byte array that is your movie (when saved to disk or database)? 我不知道下面的方法是否是最好的方法,但是您是否考虑过从电影的字节数组生成哈希值(保存到磁盘或数据库时)?

You can find some ideas on how to do that elsewhere on StackOverflow . 您可以在StackOverflow的其他位置找到一些有关如何执行此操作的想法。

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

相关问题 将小文件保存到数据库,保存它们的最佳方法是什么? - saving small files to database, what is the best way to save them? 绘制对象并对其进行处理的最佳方法是什么? - What is the best way to draw objects and deal with them? 确定收集对象的初始容量的最佳方法是什么? - What is the best way to determine the initial capacity for collection objects? 快速访问特定日期的Datetime对象的最佳集合是什么 - What's the best collection for Datetime objects with fast access to specific date C#将文本文件保存到对象的最佳方法 - C# Best Way to Save Text Files into Objects 从 2 个表中检索数据以填充在 C# 中包含另一个对象列表的对象列表的最佳方法是什么? - What's the best way to retrieve data from 2 tables for filling a list of objects that has another list of objects inside it in C#? 从有序集合中删除项目的最佳方法是什么? - What's the best way to remove items from an ordered collection? 绑定枚举(列表)的最佳方法是什么 <Enum> )到DropDownList? - What's Best way to Bind collection of Enums ( List<Enum> ) to a DropDownList? 在C#中保存RichTextFile的最佳方法是什么? - What's the best way to save a RichTextFile in C#? 在多个对象之间共享对象实例的最佳方法是什么? - What's the best way to share an instance of an object across many objects?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM