Bug #70943 Inserting data with EF6 Code First trigger an error in Mono
Submitted: 18 Nov 2013 17:15 Modified: 27 Nov 2013 23:20
Reporter: Bernard Grosperrin Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:6.8.1.0 beta OS:Linux (Mono 3.2.3)
Assigned to: Francisco Alberto Tirado Zavala CPU Architecture:Any
Tags: MARS, Mono

[18 Nov 2013 17:15] Bernard Grosperrin
Description:
The same code, which is working fine in Windows, generate an exception 
"MARS is not yet implemented!" when adding a record with a linked entity when running in Mono. Both tests are using the same, Ubuntu Linux hosted, database.

Here is a simplified extract of my code:

public static void InsertPersons()
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
            var person_0 = new Person
            {
                FirstName = "Alfred",
                LastName = "Schmoll",
                BirthDate = Convert.ToDateTime("12/03/1960")
            };

            person_0.Phones = new List<Phone>();
            var phone0 = new Phone { Type = "Home", Number = " 917 33 8745" };
            person_0.Phones.Add(phone0);
            var phone1 = new Phone { Type = "Work", Number = "315 67 8954" };
            person_0.Phones.Add(phone1);

            using (var context = new MyContext())
            {
                context.Database.Log = Console.Write;
                try
                {
                    context.Persons.Add(person_0);
                    Console.WriteLine("Person 0 added.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("----Exception Inserting 0----");
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.InnerException);
                }

Adding the switch 
context.Configuration.LazyLoadingEnabled = false;

does not change anything.

This means that, as is, the connector is not usable with Mono, as I doubt there is any difference, code first or not, about inserting data.

In fact, I went a little further and bypassed inserting data to just read from the database: I got no exceptions, but I don't see any result either, so it looks like there are serious problems with Mono.

How to repeat:
I put a sample of code above. If you would like to get my little console project to test, I would be happy to send it, but I don't see a way to upload files here.
[18 Nov 2013 17:22] Bernard Grosperrin
project showing the bug. Replace connectionstring to be correct.

Attachment: Program.zip (application/x-zip-compressed, text), 2.68 MiB.

[27 Nov 2013 19:01] Francisco Alberto Tirado Zavala
Hello Bernard.

After debug and analysis, I found that the error comes from a class in the Mono Framework: System.Data.SqlClient.SqlConnectionStringBuilder.
Here you can take a look to the class:
- https://github.com/playscript/playscript-mono/blob/master/mcs/class/System.Data/System.Dat...
- http://www.mail-archive.com/mono-patches@lists.ximian.com/msg01820.html

MARS refer to: Multiple Active Result Sets. Follow the following links for more info:
- http://msdn.microsoft.com/en-us/library/cfa084cz(v=vs.110).aspx
- http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.m...

So the exception is not related to Connector/Net but is to MonoFramework. That class belongs to Net Framework code and seems that is not fully implemented on MonoFramework.

Thanks for your time.
[27 Nov 2013 23:20] Bernard Grosperrin
Thank you for your answer, Francisco. Did you report this to the Mono Project?
[28 Nov 2013 1:01] Francisco Alberto Tirado Zavala
Hello Bernard.

No, I didn't. But as you find the issue you can report it in the following links:
- https://bugzilla.xamarin.com
- http://www.mono-project.com/Bugs

Just take in mind that the functionality is not implemented yet, so technically is not a bug is just a missing feature.

Thanks for your time.