Entity Framework 4 many-to-many

10 March 2010

I had another problem with EF4 today. Code that worked fine in .NET 3.5 didn’t work after I regenerated the entity model using Visual Studio 2010.

I found an answer, again on Stack Overflow: http://stackoverflow.com/questions/2243618/how-do-you-insert-or-update-many-to-many-tables-in-net-entity-framework

It turns out that the generator decided that one of my foreign keys in an associative table should have a StoredGeneratorPattern of Identity, meaning it thought it was an identity column. When it isn’t.

But updating the XML as suggested in the answer above fixed it. So that’s good.

Technology , ,

1..0 or 1 relationships in Entity Framework

9 March 2010

I came across this problem today when migrating a project from VS 2008/.NET 3.5 to VS 2010 RC1/.NET 4.0. I don’t actually think it’s a VS 2010 thing, though.

I have two entities A and B. There is a navigation property on A, and it can have either one or no instances of B. B’s foreign key is to A’s primary key (obviously) but B also has its own primary key. In the database, B has a unique index on that foreign key column, which will enforce the rule.

The problem when upgrading to VS 2010 occurred because I clicked the “Include foreign key columns in the model” check box when generating the model from the database. (I regenerated it because the tools might be better in 2010 so figured I should start from scratch.) That’s where my problem came from. The entity model designer wouldn’t let me change the navigation property and associated relationship from 1..* to 1..0 or 1, because the relationship had to be between the entities’ keys for that to work.

The problem only happens when you generate the model with foreign keys as their own columns. I regenerated it so that foreign key columns weren’t generated (the foreign keys were represented only as their navigation properties) and it worked fine, as it did in VS 2008.

I found this answer here: http://stackoverflow.com/questions/2141328/unique-keys-not-recognized-by-entity-framework/2326859#2326859

Hopefully this might be of some help to someone else!

Technology , , ,

Width of grouped UITableViewCell

7 March 2010

I am working on some iPhone development at the moment. I have built a cell for a UITableView in Interface Builder. The cell was a bit too wide for the cell in my table view, and I realised it was because the cell in the NIB is full width but I am loading it into a grouped table view.

I didn’t want to have to measure it myself so I searched for the width. Couldn’t find it. So I measured it myself. And put it here. So maybe I will start getting a few more visits to this page from now on!

The magic number is…

300

The width of a grouped UITableViewCell is 300 pixels.

Technology , , ,

Tab bar and navigation bar on iPhone

21 February 2010

Today I am starting to write my first iPhone application. I have finally finished reading Neal Goldstein’s book iPhone Application Development for Dummies. (I’m not going to buy another Dummies book in a hurry though: the book could have been about 30% smaller if it weren’t for the bad jokes, but I guess that’s the style of the series!) The book gave me a pretty good understanding of the basics required for iPhone development, and it was a good primer for Objective-C as well.

But I found this screencast by Elisabeth Robson at O’Reilly on how to create an application that has both a tab bar at the bottom of the screen and a navigation bar at the top. I don’t usually like screencasts because they take up too much time. But I am glad I spent 30 minutes watching this one. It was so clearly explained!

Now I can get to work building my first iPhone application (that contains a tab bar and a nav bar!)

Technology

SEO is important, even for a unique name

24 January 2010

My company is called Zemobo. It has a web site, which is currently a very basic portfolio and has a little bit of information about the free Android application I wrote, Hindi Flashcards.

It used to be that if you searched for Zemobo in Google, zemobo.com would be the first result. It makes sense, doesn’t it?

But now, unfortunately, it is quite low down on the search results. What’s ahead of it? Number 1 is a Facebook page I created for the company, which has even less information on it. And after that is androlib.com, a site that crawls Android Market and makes it viewable from the web (something that Google should have done all along, but that’s a discussion for another day).

I only noticed this yesterday, so it’s likely that Google have updated their algorithms recently.

It’s a pain though, and there’s not a lot I can do about it, at the moment. I have removed the Facebook page, so hopefully that will go from the top listing. I am going to look at androlib.com now to see if they let you place a link back to your own site. It is possible that the links on their site will lift my Google PageRank back up to where it should be.

Of course, once I have some time to spend on the web site and some more applications to talk about, I can make an efford to properly optimise the site for seach engines.

Uncategorized

Using the Android accelerometer

22 November 2009

I am building my first real Android application. It is a Hindi flashcards application. It works already (in that it will shows the different Devanagari characters and English transliterations) but now needs some better UI features.

The first one I am going to implement is shuffling the deck of cards by shaking the phone, using its accelerometer. To handle accelerometer events, you need to get a reference to the SensorManager and then register a new SensorEventListener using the registerListener method:

SensorManager sensor = (SensorManager)getBaseContext().getSystemService(SENSOR_SERVICE);

sensor.registerListener(new SensorEventListener() {
	@Override
	public void onSensorChanged(SensorEvent event) {

	}

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {

	}
}, sensor.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_UI);

I figured out the rest of it from a forum on anddev.org: http://www.anddev.org/viewtopic.php?p=26929.

I haven’t tried it, but I’m guessing it will work. Looks like it combined the x, y and z acceleration, and checks that the current and previous values of the combined acceleration are before and after a predetermined threshold. I think there’s some intelligent physics involved in that but it’s been 10 years since I learnt any physics!

One thing wrong with the post on anddev.org is that it’s using an old version of the Android API.

The next post will be about using a slide motion on the touch screen to move between cards (without animation, though).

Technology

PNGs in IE6

29 October 2009

My preferred way of dealing with IE6’s limitations on transparent PNGs is to use conditional comments and the AlphaImageLoader filter. This is because it requires the least processing on the browser, and works without JavaScript enabled.

There are three problems with it. First up, you have to create a CSS rule for every PNG that you want to replace:

.class
{
   background-image: none;
   filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/transparent.png', sizingMethod='scale');
}

The second problem is that images in that file have to be relative to the page, unlike normal CSS background images whose URLs are relative to the CSS file.

And the final problem is that it only works for background images. You can’t replace <img> tags with this method alone.

A solution to this would be a magic script that could take an existing CSS file, look at all the background-image styles, and generate an IE6-specific stylesheet that has absolute URLs and all the AlphaImageLoader filter statements.

Does something like that exist already? Let me know in a comment.

If it doesn’t, would you think it would be useful? I might write one.

Technology

Annoying spacing problem with Flash <object> tag

14 July 2009

Not sure if this is SWFObject-related or Flash-related or <object> tag in general-related, but I was working on a page today and in Firefox a 4 or 5 pixel gap. According to the FAQ for SWFObject (item 11), to fix it, you just have to set display:block on the object tag.

Simples!

Uncategorized

Sky+ in the UK when you’ve only got one satellite feed

30 March 2009

So I recently moved flat and used to have Sky+ in the old flat. Sky+ (which is the same as MySky in NZ) needs two feeds from the satellite dish, so you need a dual LNB. I have one feed coming down from what I think is a communal dish on the roof of the building. I have actually quit Sky because it’s too expensive, but it’s still running till the end of the billing month so I may as well use it.

But, oddly, not all channels will work. I rang up Sky and they are going to resend the codes or whatever to authorise the smart card, but it hasn’t worked (yet).

The odd thing is that the channels that don’t work (I get a message telling me to call them to upgrade my subscription on channels like Sky Sports and even Five) can record using the Sky+ feature, and I can play them back as well. Doesn’t make much sense to me.

I imagine though that it has something to do with polarity. The channels that don’t work are horizontal. But some channels that are horizontal do work.

It’s very odd, and I don’t really mind seeing I am getting rid of the subscription, but I thought I’d write something here to see if someone else had a similar complaint and maybe someone will offer a solution. I might get a splitter and some more cable and plug the cable into both inputs on the back of the box. It may well fix the problem, but both LNBs will only be able to see the same polarity anyway, so that could just break everything. We will see!

UPDATE: Once the card was reauthorised, it worked properly. So obviously nothing to do with polarity.

Technology ,

AJAX history with ASP.NET AJAX 1.0

27 March 2009

If you are still using the original ASP.NET AJAX 1.0 release, you may be looking for a way to use .NET 3.5 SP1’s “history” feature of the ScriptManager control.

A while back, Nikhil Kothari wrote a component called UpdateHistory, which looks like what was integrated into 3.5 SP1. It certainly solved my problem.

Combine it with HttpUtility.ParseQueryString and you’re onto a winner!

Technology , ,