Sunday, January 19, 2014

Entity Framework 6 + Stored Procedure = The type or namespace name 'Objects' does not exist in the namespace 'System.Data'

(this post is formatted poorly, it will be fixed later because I really need to post this one before I forget it)

On my latest project I upgraded to Entity Framework Version 6 and everything was fine until I tried to add a Stored Procedure function import.

After adding that I could no longer build the project and the error message of "The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)" started showing up.

I found the solution here and the fix is to download the Entity Framework 6 Tools for Visual Studio 2012/2013.

Note:  After you install the tools, your model will still not compile.  To fix it you must either:

  • Delete and re-add the Model.edmx to your project
OR
  • Create another model and copy the Context.tt file from it over your initial model.  After you copy the .tt, on Line 5 you'll need to set the name of your original Model.edmx
Line 5: const string inputFile = @"OriginalModel.edmx";
Now, after it compiled I ran into the fun error message "System.InvalidOperationException: The value of EntityCommand.CommandText is not valid for a StoredProcedure command. The EntityCommand.CommandText value must be of the form 'ContainerName.FunctionImportName'."  At this point I was almost ready to write EF6 off as unusable, but I found a page at http://www.dotnetbits.com/entity-framework-6-t4-templates/ that gave me the updates to Context.tt that I needed.

Look for the method signature

public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)

Replace that method with

public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
{
var parameters = _typeMapper.GetParameters(edmFunction);
var returnType = _typeMapper.GetReturnType(edmFunction);
var callParams = _code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()));
if (includeMergeOption)
{
callParams = ", mergeOption" + callParams;
}
return string.Format(
CultureInfo.InvariantCulture,
"return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction{0}(\"{1}\"{2});",
returnType == null ? "" : "<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">",
edmFunction.FullName,
callParams);
}

Monday, September 30, 2013

Create an ad-hoc network in Windows 8

My USB drive died and I needed a very quick way to get some larger files from my tablet to my laptop.  The largest problem was that I was connected over an open WiFi network in my hotel room and I needed it to be as secure as I could make it.

So, creating an ad-hoc network came to mind between my laptop and tablet to transfer the files.  I have never actually had a need to create one of these, but the steps are more manual than I remember them being in previous versions of Windows.

I found my answer at http://www.addictivetips.com/windows-tips/how-to-create-wireless-ad-hoc-internet-connection-in-windows-8/  The site has detailed steps and pictures if you need them, so I'll give a very quick run-down of what needs done.

Notes:

  • Your NIC needs to support virtualization (see the website for more info).  Any modern NIC should support it, however.
  • Your ad-hoc network will broadcast a public SSID.
  • The encryption is WPA-2 Personal.
  • Copying between the tablet and the laptop is pretty slow, but it works over a network share that I made.
To enable it:
  1. From a command prompt run:
    1. netsh wlan set hostednetwork mode=allow ssid=NETWORK_SSID key=PASS_KEY
    2. netsh wlan start hostednetwork
  2. Open up the network adapter list, you can search for "View Network Connections" in the Windows 8 search.
  3. Enable Internet Connection Sharing (ICS) by going to the Network Adapter properties you want to share (the same place you'd assign an IPv4 static IP at) and choose the Sharing tab.  Then just enable it to be shared by others.
  4. Look for your SSID on your other device(s) and connect to it.

Friday, September 20, 2013

Xbox 360 Sign-in Error 80072EF3 and other ailments

I've had all kinds of problems with one of my Xbox 360s in particular, the 4GB with Kinect newer model , but not the latest version that looks like the Xbox One .  This thing had been through about every beta invite and set in my son's room for over a year doing who knows what.

Some of the things I was experiencing:

  • Random popups asking for me to enter my security information and password when a profile is signing in.
  • Random disconnects from Xbox Live
  • Constant freezing during game play and movie watching
    • Sometimes there would be no indication other than a frozen screen
    • Sometimes it would display vertical blue broken lines on the screen
    • Sometimes it would display vertical red broken lines on the screen
  • And finally the inability to connect completely with 2 of the 4 profiles on the Xbox with Error 80072EF3 required me to do some research 
I had honestly written off all the problems as the thing was dying.  I assumed my son had done something, like let it get too hot, causing the video card to just start the path to death.

I found a lot of suggestions ranging from delete the cache to delete the profiles and re-download them for the disconnects and the 80072EF3 error.  Something was corrupted and the most likely assumption was the profiles.  The only suggestions about the freezing with the vertical lines was to send my Xbox in for warranty because the video card is about to die.

In the end none of that worked. Finally I found a few places suggesting to just do a system software reset.  I'm sure some have never heard of this, but back in the day it was the only way to reset the cache as well. Microsoft likes to "give you a good user experience", forcibly usually.  Hey, just like the Windows 8 User Account Control being mandatory to use and create Metro (yeah I know it isn't called that anymore) applications causing me to never be able to double click files to open them in Visual Studio.  Ok, I'm done with that complaint and onto the rest of this post.

Now onto the Steps:

Go to Settings, Storage, and highlight any of your storage devices.  Then press the magic buttons.
  1. Left Bumper
  2. Right Bumper
  3. X Button
  4. Left Bumper
  5. Right Bumper
  6. X Button
Restart your console and it will download the latest software version again.

This sequence is available all over the internet, but I'll give credit to a user post on the Xbox forums as it last place I looked it up.

Create a bootable USB drive from a bootable ISO image

It seems I'm always wanting to make a bootable USB drive my an ISO I have, but I never remember where I found the tool.

Microsoft provides a free tool Windows 7 USB/DVD download tool that does the job.

Friday, September 6, 2013

Automatically add "maxlength" attribute to MVC validation textboxes

We needed the maxlength attribute added to all of our text boxes, but there was no obvious way to do it while using the built-in MVC validation.

I found this bit of JavaScript at http://sharpercoder.blogspot.com/2011/04/validation-set-maxlength-of-text-box.html that takes care of it automatically by adding the maxlength attribute to any input objects that contain the data-val-length-max attribute already.

<script type="text/javascript">
    $(document).ready
    (
        function () {
            $('input[data-val-length-max]').each
            (
                function (index) {
                    $(this).attr('maxlength', $(this).attr('data-val-length-max'));
                })
        });
</script>

Monday, August 19, 2013

Windows Phone 8 IE 10 Responsive Design Fix

It seems that WP8 with IE10 has a bug with responsive design viewports.  I found the widely used fix at http://timkadlec.com/2013/01/windows-phone-8-and-device-width/


Add the following CSS:

@-webkit-viewport{width:device-width}
@-moz-viewport{width:device-width}
@-ms-viewport{width:device-width}
@-o-viewport{width:device-width}
@viewport{width:device-width}
 
Add the following JavaScript:
<script type="text/javascript">
    if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
        var msViewportStyle = document.createElement("style");
        msViewportStyle.appendChild(
            document.createTextNode(
                "@-ms-viewport{width:auto!important}"
            )
        );
        document.getElementsByTagName("head")[0].
            appendChild(msViewportStyle);
    }
</script>

Monday, August 12, 2013

Change a Windows 8 Product Key

I purchased a large number of Windows 8 Update Keys, but I needed clean installs of Windows 8 on each machine.

Instead of something like "Enter your previous Windows Key" to install it, Microsoft decided to not let the install proceed without the previous version already existing.  I needed a way to change the product key after a clean install with an image copy without installing a previous version of Windows again for every computer.

I found a lot of solutions that sometimes worked, sometimes not.  The one that seemed to work every time for me I found at the Microsoft Community Forums.

The steps are:

  1. Run the registry editor (regedit.exe) 
  2. Find the following key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\OOBE 
  3. Change the value for the key MediaBootInstall from 1 to 0 
  4. Open an elevated command prompt by Running as Administrator
  5. Run slmgr -rearm 
  6. Reboot your computer
  7. Run slui 3
  8. Change your product key and activate Windows