|
Post by maxresdefault on Sept 3, 2020 0:09:43 GMT
Hi there, So with our database structure we have relationships between classes, and objects storing multiples of other classes. For example, a 'Region' class might have a list of 'Enemies' that spawn in it (1-* relationship).
As of testing the system out we can get all of the regions and then get all of the enemies in a separate query with:
SELECT e.id, e.data, e.ether_stuff FROM enemy e JOIN region_enemy_link l ON e.id = l.enemy_id JOIN region r ON r.id = l.region_id WHERE r.id = 1 However this is two calls to the query and it would be much nicer if the list of enemies could be serialized from the DB in the Region query.
I've tried doing a big SELECT statement and supplying all of the values it would need but the DBManager tells me it can't read the class type.
This is understandable if it can't do it, but I just wanted to check. Thanks
|
|
|
Post by echo17 on Sept 4, 2020 13:38:01 GMT
I'm not sure what your specific requirement is, but you could set up an ORM class like:
public class RegionEnemies { // enemy fields public int e_id { get; set; } public string e_data { get; set; } public string e_ether_stuff { get; set; }
// region fields public int r_id { get; set; } public string r_name { get; set; } // or whatever fields you have in region }
and then set up a query like:
SELECT e.id e_id, e.data e_data, e.ether_stuff e_ether_stuff, r.id r_id, r.name r_name FROM enemy e JOIN region_enemy_link l ON e.id = l.enemy_id JOIN region r ON r.id = l.region_id WHERE r.id = 1
|
|
|
Post by maxresdefault on Sept 8, 2020 7:56:36 GMT
Thanks for the quick reply! We don't want to retrieve the enemy fields (like name), we want to retrieve the enemy object. This can be done with multiple queries (i.e. retrieving the regions and then the nested enemies) but it seems like de-serializing two classes with one query is not something that can be done?
Thanks
|
|