|
Post by karcfa on Feb 23, 2022 23:02:31 GMT
public class ItemData
{
[ShowInInspector] public string name { get; set; }
}
Is there a way to make SimpleSQL work without get; and set; written? Other asset im using is simply not compatible and giving up on either asset is very troublesome at the least
I dont understand why do I have to write this part { get; set; } ?
For clarification: without it, it doesnt see variables of class FrameData when I do this foreach (FrameData frame in editorSQLManager.Query<FrameData>("SELECT * FROM FrameData")) and thus variables, e.g name var, returns "" (empty)
or theres syntax error when i do Insert
|
|
|
Post by echo17 on Feb 24, 2022 14:28:16 GMT
The get; set; combo on properties is for reflection, which the ORM uses to map your class properties to database fields. This is a .NET requirement.
If your code isn't compatible with this, then you could do a couple of things:
1) Set up other members that won't be used in the mapping, but can be used in your code. Behind the scenes, use those members in your properties:
public class ItemData
{
[ShowInInspector] public string name;
public string DB_name { get { return name; } set { name = value; } } }
You would need to have your database field names set to match the ORM names, so in the above example, your database field would be called DB_name instead of name (it just has to be something unique, so DB_name is an example).
2) Don't use ORM at all (and no reflection). Instead do your queries manually, like:
var sql = "SELECT name FROM MyTable"; var myTable = dbManager.QueryGeneric(sql); foreach (SimpleSQL.SimpleDataRow dr in myTable.rows) { Debug.Log(dr[0].ToString()); }
|
|
|
Post by karcfa on Feb 24, 2022 14:58:43 GMT
The get; set; combo on properties is for reflection, which the ORM uses to map your class properties to database fields. This is a .NET requirement. If your code isn't compatible with this, then you could do a couple of things: 1) Set up other members that won't be used in the mapping, but can be used in your code. Behind the scenes, use those members in your properties:
public class ItemData
{
[ShowInInspector] public string name;
public string DB_name { get { return name; } set { name = value; } } }
You would need to have your database field names set to match the ORM names, so in the above example, your database field would be called DB_name instead of name (it just has to be something unique, so DB_name is an example). 2) Don't use ORM at all (and no reflection). Instead do your queries manually, like:
var sql = "SELECT name FROM MyTable"; var myTable = dbManager.QueryGeneric(sql); foreach (SimpleSQL.SimpleDataRow dr in myTable.rows) { Debug.Log(dr[0].ToString()); }
thanks
|
|