Asp.NET MVC3 + MySQL, always returns null
I am at a loss with this one. First of all, something strange:
every time I open a connection, (as shown in mysql logs), the following commands are excecuted:
SET character_set_results=NULL
SET NAMES utf8
SHOW COLLATION
SHOW VARIABLES
Then there is no select query at all!
A simple:
usin开发者_如何学Cg (MyEntities myents = new MyEntities())
{
var lala = (from r in myents.categories
select r).ToList();
}
Will produce an error: Object reference not set to an instance of an object.
Even a .FirstOrDefault() produces the same error! (it should return null in case of empty dataset).
I think I broke asp.net!
Asp.net ver 4 MySQL connector 6.4.3 MVC 3 controller (same result is also inside a repository class etc)
Have you specified the ConnectionString
correctly in the top level Web.config
or App.config
(i.e. the one that features the above code)?
Debug and try to find out if it's your MyEntities
that is null
or something else.
Looks like I found the cause of mayhem, but why this bug occurs beats me: (evil) NUGET added this:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
[...]
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.4.3.0" newVersion="6.4.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Deleting this from the config makes everything fine and dandy!
精彩评论