开发者

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

开发者 https://www.devze.com 2023-04-12 20:58 出处:网络
I have a collection of Movie objects in a HashSet<Movie>. Movie type has properties such has Name, Year, Length, Genre, etc.

I have a collection of Movie objects in a HashSet<Movie>. Movie type has properties such has Name, Year, Length, Genre, etc.

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开发者_Python百科 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.

The User class would then have a list of Guids that represent the movies connected as favorites (or you can preload this with the actual movie objects)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消