Error when trying to delete entity in Entity Framework 4

I was getting an error message in Entity Framework 4 when I was trying to delete an entity.
The entity had a relationship to another entity, so when I tried to delete the parent entity my child entity would have had a reference to an entity that didn’t exist.

What I want is when I delete the top entity the child entity should also be deleted; this is called cascade delete.

This webpage describes the mechanics behind it, it worked for me and is a great write-up:
http://blogs.msdn.com/b/alexj/archive/2009/08/19/tip-33-how-cascade-delete-really-works-in-ef.aspx

Unable to update the entityset because it has a definingquery and no insertfunction

I was trying to insert a record into a table using Entity Framework 4 (EF 4) and got this error message back from the data store.

I did a couple of bing and google queries and found the following links:
http://stackoverflow.com/questions/1589166/it-has-a-definingquery-but-no-insertfunction-element-err

Although it seemed strange that I received this error message now, I have never every before had any issues with inserting records.

I started to look at the table I was trying to insert records to and I found that the table was missing a primary key.
After adding the primary key, I did not receive this message again.

Android Creating Notification Icons, Menu Icons, Launcher icons, Menu icons, Action bar icons (Android 3.0+), Tab icons; Android Asset Studio

A great tool to create a set of different icons, it is called Android Asset Studio:
http://android-ui-utils.googlecode.com/hg/asset-studio/dist/index.html

A great tool to create

  1. Launcher icons
  2. Menu icons
  3. Action bar icons (Android 3.0+)
  4. Tab icons
  5. Notification icons

It works best in Google Chrome

ASP.NET MVC 3 Unable to install using Microsoft Web Platform Installer

After watching some videos from PDC, MIX 11 and Tech-Ed 2011 I wanted to install ASP.NET MVC 3.
This should now be very easy with the Web Platform Installer, well it wasn’t.

It appears as though there are some registry changes made when you install Visual Studio 2010 SP 1 thats makes it impossible to install ASP.NET MVC 3.

The cause of the problem is that Microsoft ASP.NET Web Pages is installed and the uninstaller is unable to to uninstall the old version and install a new version of ASP.NET Web Pages.

Fortunately there is a solution to the problem, four steps:

  1. Remove the trailing backslash from the following registry keys:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\4.0.30319.0\Path

    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ASP.NET\4.0.30319.0\Path

  2. Uninstall the old version of Microsoft ASP.NET Web Pages.
  3. Add the trailing backslash back to those keys.
  4. Install MVC 3


That worked for me, does it work for you?
Source: http://connect.microsoft.com/VisualStudio/feedback/details/650729/can-not-install-mvc-3

Android an easier way to test that a service that should start at device boot; starts

Earlier I wrote a blog post about how to test that an Android service starts at device boot. Well there is an easier way to start a virtual device.

Start the Android SDK and AVD Manager, it is located in your Windows Android SDK folder. The file name is SDK Manager.exe. Select Virtual devices.

image

Once you have started the SDK and AVD Manager, select the virtual device you used to test your application/service from your IDE (Eclipse, IntelliJ); press Start… If you have programmed your application and service correctly; the service should now start when you start your virtual device.

Android How to test that a service that should start at device boot; starts

Developing Android services that should start when the phone is started (after boot-up) is very easy and is very convenient for the user.

It is especially convenient for the user, because, if the service sits in the background and does its thing with minimal user interaction; it could be hard for the user to remember to start the service when the phone is restarted.

Here is a tutorial on how to get the functionality of a service starting at device boot:
http://blog.gregfiumara.com/archives/82

Well how do we actually test in the emulator that it works?

  1. Develop your android activity and service using the tutorial above
  2. Compile the application and start the emulator from you favorite IDE (Eclipse or IntelliJ)
  3. Make sure the application can start the service

After these steps the application is stored on the emulator and the service is registered to start when the device boot. What we have to do is to start the emulator but no inside of our IDE (Eclipse or IntelliJ)

How do we do this?

  1. Locate where you installed your Android SDK (in my case C:\Program Files\Android\android-sdk-windows)
  2. Open the tools directory within the Android SDK folder, in this folder there should be a file called emulator.exe
  3. Start the command promt; Start Meny -> Run -> cmd.exe
  4. Navigate to the tools directory in step 2, command: cd C:\Program Files (x86)\Android\android-sdk-windows\tools
  5. Before you start the emulator you have to decide which emulator to start. I have two emulators named AAVD1, AAVD2. You want to start the same emulator that was launched when you launched the emulator from your IDE. In my case it was AAVD2.

From the command prompt you should now start the emulator with this command:
C:\Program Files\Android\android-sdk-windows\tools>emulator -avd AAVD2

Now you should see your service start at device boot.

You could also start you emulator from the SDK Manager (SDK Manager.exe) which i located in the Android SDK directory.

WCF Duplex Service Deadlock

I was creating a WCF duplex service and was experiencing some weird behavior.
The service was sending messages to the client (duplex) but as soon the client (any client) wanted to unsubscribe to the service, hence, stop recieving messages; the service and all clients would freeze.

After some binging and googling I found a solution, it seems that there is such a thing as Synchronization Context; by setting this attribute to false all problems solved.

You need to set this attribute on your class implementing the WCF service callback

[CallbackBehavior(UseSynchronizationContext = false)]
public partial class Form1 : Form, IMyServiceCallback
{
	IServiceService proxy;
	public Form1()
	{
		InitializeComponent();
	}
}

More in-depth information provided in these articles:
http://www.aaronmurrell.com/ThinkBlog/WCFThreadSynchronizationContext.aspx
http://msdn.microsoft.com/en-us/magazine/cc163321.aspx

Android Split Horizontal Tablelayout 50 % width

I was trying to figure out how to create an Android view with a tablelayout that was split in half:
|control| control|
|control | control|

It took some time, but i figured out it is pretty simple; the key is to use a linearlayout with orientation horizontal:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 
	xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >
	<LinearLayout 
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    	
    	<LinearLayout 
	    android:orientation="horizontal"
	    android:layout_width="fill_parent"
	    android:layout_height="wrap_content">
			<LinearLayout 	
				android:layout_weight="1" 
				android:layout_height="fill_parent" 
				android:layout_width="fill_parent" 
				android:orientation="vertical">
				<TextView 
					android:text="User Applications" 
					android:layout_width="wrap_content" 
					android:layout_height="wrap_content" />
				<TextView 
					android:id="@+id/tvUserApplications" 
					android:layout_width="wrap_content" 
					android:layout_height="wrap_content" />
			</LinearLayout>
			
			<LinearLayout 
				android:layout_weight="1" 
				android:layout_height="fill_parent" 
				android:layout_width="fill_parent" 
				android:orientation="vertical">
				<TextView 
					android:text="System Applications" 
					android:layout_width="fill_parent" 
					android:layout_height="wrap_content" />
				<TextView 
					android:id="@+id/tvSystemApplications" 
					android:layout_width="wrap_content" 
					android:layout_height="wrap_content" />
			</LinearLayout>
		</LinearLayout>
    </LinearLayout>   
</ScrollView>

This code snippet will create a view with tablelayout with two rows split in two (two columns) each having 50 % width with a textview inside of each column.

The key point is to define android:layout_weight=”1″ for each LinearLayout.

Happy coding.