0

I am making project in Unity3D using MySQL server. How can I make SQL-queries using LINQ? Because Unity3D working with .net 2.0 there is no way to use EntityFramework or smth like that, so I am have to type SQL-query by myself like that:

    var command =
        "INSERT INTO `person` (`surname`, `name`, `patronymic`, `login`, `password`, `category`, `organization`, `city`) VALUES ('" +
        surname +
        "','" + name + "','" + patronymic + "','" + login + "', '" + encrpass + "','" + category + "','" +
        organization + "','" + city + "');";

    try
    {
        var cmd = new MySqlCommand(command, Connection);
        cmd.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
        Debug.Log(ex.ToString());
    }

Whether there is a more simple way to use MySQL from Unity? Thanks.

  • If you can't use EF, how do you expect to use LINQ? In any case, you should *NEVER* concatenate values. Use parameterized queries – Panagiotis Kanavos Oct 19 '16 at 07:58
  • Do not use MySQL directly from your app. [This](http://stackoverflow.com/a/38530543/3785314) explains why and the other option – Programmer Oct 19 '16 at 08:06
  • @Programmer, this app will work only in office local network, so I`m not caring at all about security. – Konstantin Zhuk Oct 19 '16 at 08:11
  • @Programmer the linked question doesn't explain anything related to *this* question. – Panagiotis Kanavos Oct 19 '16 at 08:12
  • Dapper.NET works on Mono, as [explained in this SO question](http://stackoverflow.com/questions/7934757/does-dapper-work-on-mono) – Panagiotis Kanavos Oct 19 '16 at 08:12
  • Unity is using Mono, which *does* support LINQ. .NET 3.5 is actually 2.0 with extra libraries anyway. – Panagiotis Kanavos Oct 19 '16 at 08:24
  • @PanagiotisKanavos My comment is saying that OP needs to do this in another way instead of the current way or the linq way for security reasons. My comment and the linked answer would still be valid but OP said this is only in-house app which makes it fine. That answer would have been useful if this program will be released on app store. – Programmer Oct 19 '16 at 08:27

2 Answers2

1

Have a look at LinqToDb. It also has a version for Mono and it should work with Unity3D.

Good luck.

korn3l
  • 143
  • 10
0

For using LINQ in Unity you can check this thread and see if it helps you.

Cheers.

Community
  • 1
  • 1
Emiliano
  • 39
  • 1
  • 7