Unable to update the EntitySet because it has a DefiningQuery and no InsertFunction element exists

While working with SQL Server and Entity Framework the following error was raised after adding a new table into the SQL Database and updating the model in my project from the DB:

"Unable to update the EntitySet 'Customers' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation."

The error was raised as an exception on calling the SaveChanges method on the context after adding a new record into a list/ table on the database.

The solution to the problem was simple – although my new SQL table had an ID column, I hadn’t set the column as the primary key. Setting the column as a primary key in SQL Server Management Studio then going back to my Visual Studio project and rebuilding the entity model from the database made the error go away and let me successfully save new records to the table.

One click to maximize Internet Explorer from the Task Bar

On the whole I prefer using Microsoft’s Internet Explorer to Firefox, but one of IE’s most annoying default features for me is that when you have a few tabs open showing different web pages and you want to click on IE in the task bar in Windows 7 in order to maximize IE and show the last web page you were looking, Windows shows a list of all your open tabs, forcing you to pick a specific tab. I’ve no idea why this is the default behaviour in IE as it mean you have to find the last web page you were looking at in the list then click again to maximise the web page in IE.

However, you can change this behaviour and make IE work like Firefox and simply maximize with the last page you were looking at with one click on IE in the task bar.

To change the setting, do the following …

1. Run Internet Explorer.

2. Press the Alt key on your keyboard so that IE shows its main menu at the top.

3. Click on the Tools menu and choose the Internet Options menu option.

IE will then show the Internet Options dialog.

4. Click the Settings button in the Tabs section as shown in the picture below.

internet-explorer-tabs-options

IE will then show the Tabbed Browsing Settings dialog.

5. In the Tabbed Browsing Settings dialog, uncheck the option “Show previews for individual tabs in the taskbar” as shown in the picture below.

tabbed-browsing-settings6. Click OK to close the options dialogs, then close IE and reopen it.

Now, IE maximises from the taskbar in a single click.

For more Windows tips, see:

http://www.sliqtools.co.uk/blog/windows-help/windows-8-how-to-set-live-mail-as-the-default-email-client/

SliQ Invoicing Plus Version 4 Released

Version 4 of SliQ Invoicing Plus has now been released, 18 months after the release of version 3. Version 4 includes a range of updates requested by our users as well as a refresh in the look of the package.

In version 4, even more flexibility has been included and now customers can customise the standard reports or even copy the reports to create whole new reports. As with our previous versions, all our reports can be exported to Microsoft Excel. Reports can be customised by adding more columns, filtering and sorting any of the columns as well as adding custom groups.

Going along with the theme of increasing flexibility, all the major lists shown in SliQ can also now be customised, e.g. the Invoices & Payments tab list can be customised by adding the invoice delivery address.

The recurring invoices facility has also been overhauled and in V4 it is now possible to create recurring transactions. The new recurring transactions facility makes it easy to change tax rates in the middle of a recurring billing cycle, e.g. if the VAT rate changes.

Many more new features are included in V4 including sales receipts, a sales margin calculator, support for multiple addresses and delivery addresses per customer or supplier, multiple contacts per customer/ supplier, customer price bands and a wizard to help assign customer payments to multiple invoices.

As with our previous major releases, a program of updates is planned on a regular cycle over the new few months.

Version 4 is available for a one-off price and includes a free 30 day trial. V4 is 100% compatible with all previous versions from V1 to V3 and will automatically import and convert all data and settings from older versions when installed on the same PC as a previous version.

For more information on the new features in version 4, check out our Release History page.

Monotouch Exception: This class is not key value coding-compliant …

While writing an iPad application in Monotouch I started getting the following exception while running the program in the iPad simulator:

Objective-C exception thrown.  Name: NSUnknownKeyException Reason: [<MainView 0x99d1460> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key buttonSetup.

Stunned by how unhelpful the exception message was I tried to track down the cause of the error. The only clue the error message gave me was that buttonSetup was the name of a UIButton I had previously had on my main view in the application. However, I had renamed the button so theoretically there were no references to the button left in the project. After reopening the xib for the view in XCode, I tried to track down any remaining reference to the button with no luck until after a few minutes clicking round, I found the following view in Xcode – the Connections Inspector view – which showed a remaining reference to the old button name in the Referencing Outlets:

monotouch-remove-referencing-outlet

To get to the Referencing Outlets section, I clicked on the renamed button (in the pane shown on the left in the pic. above) then opened the Connections Inspector using the toolbar button shown on the top right in the pic. The red rectangle on the bottom right shows the extra referencing outlet to the old control name that I had to remove to get the project to run without an exception. Removing the buttonSetup referencing outlet was easy – just click the x on the File’s Owner widget.

SQLite: How to get the row ID after inserting a row into a table

When working with SQL databases it can often be useful to keep a record of the ID of the row in a table from which a piece of data was read. For example, if you have a Customers table in a database then if you populate a list of Customer objects in your application from the rows in the table, storing the row ID for each object lets you easily update the correct row if you edit the values in one of the Customer objects.

In SQLite, if you have a field of type INTEGER PRIMARY KEY in a table, the database engine will automatically fill the field with the ID for the row. When you insert a new row in the table, e.g. add a new customer into the Customers table taking the example above, then you will need to find out the ID of the new row so you can write it back into the Customer object you’ve just added.

SQLite has a special SQL function – last_insert_rowid() – that returns the ID of the last row inserted into the database so getting the ID of a new row after performing a SQL insert just involves executing the last_insert_rowid() command.

Here is an example in C# showing how to get the ID of the last row inserted into a table in a database.

Create the SQLite database and open a connection to it:

 String mPathName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "testdba.db3");

 SQLiteConnection.CreateFile(mPathName);

 // Open a connection to the database.
 SQLiteConnection Conn = new SQLiteConnection("Data Source = " + mPathName);

 Conn.Open();

Create a table (Customers) in the SQLite database:

 // Create a table.
 //
 String SQL = "CREATE TABLE Customers (ID INTEGER PRIMARY KEY, UNIQUEID VARCHAR(30), ADDRESS VARCHAR(100))";

 SQLiteCommand Command = new SQLiteCommand(SQL, Conn);

 // Create the table.
 //
 Command.ExecuteNonQuery();

Insert a row of data into the table:

 // Reuse the command object and insert a row into the table.
 //
 Command.CommandText = "INSERT INTO Customers (UNIQUEID, ADDRESS) VALUES (@UNIQUEID, @ADDRESS)";

 Command.CommandType = System.Data.CommandType.Text;

 Command.Parameters.Add(new SQLiteParameter("@UNIQUEID", "Fred Bloggs"));
 Command.Parameters.Add(new SQLiteParameter("@ADDRESS", "Acacia Avenue"));

 int Status = Command.ExecuteNonQuery();

Now get the ID of the last row inserted:

 Command.CommandText = "select last_insert_rowid()";

 // The row ID is a 64-bit value - cast the Command result to an Int64.
 //
 Int64 LastRowID64 = (Int64)Command.ExecuteScalar();

 // Then grab the bottom 32-bits as the unique ID of the row.
 //
 int LastRowID = (int)LastRowID64;

Note that in SQLite the row ID is a 64-bit integer but for all practical database sizes you can cast the 64 bit value to a 32-bit integer.

For more SQLite database tips check out:

http://www.sliqtools.co.uk/blog/net/sqlite-how-to-determine-if-a-columns-exists-in-a-table/

SQLite: How to Determine if a Column Exists in a Table

As part of developing a new application using the SQLite database I need to perform some standard database checks when the application starts. Firstly I need to check that the application’s database exists and then either create the database if it doesn’t exist, or, if the database does exist, check that the tables in the SQLite database contain the columns expected by the app.

Checking whether the Database Exists

Checking that the SQLite database exists is easy, I can simply use code like:

if (!File.Exists(mPathName))
{

i.e. I can use the normal System.IO methods in .Net to check whether the database is present.

Creating a SQLite Database

Creating a SQLite database is also straightforward in SQLite. I can create the database file as follows:

// Create the database file.
SQLiteConnection.CreateFile(mPathName);

// Open a connection to the database.
using (SQLiteConnection Conn = new SQLiteConnection("Data Source = " + mPathName))
{
    Conn.Open();

    // Create the required tables. In this example, I'm creating a Customers table with 3 fields - ID, UNIQUEID and DATAFIELD.
    String SQL = "CREATE TABLE Customers (ID INTEGER PRIMARY KEY, UNIQUEID VARCHAR(30), DATAFIELD VARCHAR(100))";

    using (SQLiteCommand Command = new SQLiteCommand(SQL, Conn))
    {
       Command.ExecuteNonQuery();
    }

    Conn.Close();
}

This is all pretty standard SQL and ADO.Net.

Checking if Columns Exist in the SQLite Database

Checking whether columns exist was a little harder to work out for SQLite. Some other databases I’ve used has special methods to get the tables, columns and their attributes. SQLite didn’t have a class to enable me to do this quite so obviously but after some research and experimentation, I found the following code worked:

// Open a connection to the database.
using (SQLiteConnection Conn = new SQLiteConnection("Data Source = " + mPathName))
{
    Conn.Open();

    // Get the schema for the columns in the database.
    DataTable ColsTable = Conn.GetSchema("Columns");

    // Query the columns schema using SQL statements to work out if the required columns exist.
    bool IDExists       = ColsTable.Select("COLUMN_NAME='ID' AND TABLE_NAME='Customers'").Length != 0;
    bool UNIQUEIDExists = ColsTable.Select("COLUMN_NAME='UNIQUEID' AND TABLE_NAME='Customers'").Length != 0;
    bool ElephantExists = ColsTable.Select("COLUMN_NAME='ELEPHANT' AND TABLE_NAME='Customers'").Length != 0;

    Conn.Close();
}

A statement like

ColsTable.Select("COLUMN_NAME='ID' AND TABLE_NAME='Customers'")

returns an array of DataRows. If the column doesn’t exist an array of length 0 will be returned, hence the .Length != 0 check.

Adding a Column if it doesn’t Exist in the SQLite Database

Adding a column to a SQLite database can be performed using standard SQL statements.

String SQL = "ALTER TABLE Customers ADD COLUMN ELEPHANT VARCHAR(100)";

using (SQLiteCommand Command = new SQLiteCommand(SQL, Conn))
{
    Command.ExecuteNonQuery();
}

It turns out that performing these basic operations on a SQLite database is pretty straightforward when you know how. One thing I haven’t bothered to find out yet is to determine whether a column has the correct attributes, e.g. my example ELEPHANT column may change from a 100 character to a 200 character wide column between different versions of the application. However, I’ve never had a good reason for doing such a database update in the past. I’m also relying on the SQLite feature where the database will store any sort of data of almost any length in any column.

For more SQLite tips, see:

http://www.sliqtools.co.uk/blog/technical/sqlite-how-to-get-the-id-when-inserting-a-row-into-a-table/

Human-Centered Design – An Introduction to Designing for Ease of Use

Designing products that are easy to use is not a simple exercise. After a number of years spent designing a range of PC and industrial products, my experience is that those products which appear the simplest, cleanest and easiest to use are, more often than not, the ones that took the most amount of effort to design and complete. Constructing a product that simply exposes every possible feature at once to the user is relatively easy. What’s more difficult is prioritising the user interface, making the most frequent and essential elements readily available while pushing the more advanced, less frequently used features into the background.

human-centred-design

One of the biggest obstacles to overcome when beginning to design anything that is easy to use is the designer’s ego. Almost all designers, whatever their field, e.g.  software, mechanical, usually hold some sort of innate belief about what the user wants and what the best solution should be. This is a natural and essential requirement for any designer. Without the self-belief and initiative to construct a solution a designer would not be able to form an innovative solution for a user need. However, in any mature development process, the ultimate design of a product should not be allowed to rely on what may turn out to be a prejudice, personal desire or pet theory of the loudest or most assertive engineer (or manager) on the team.

One process that can be adopted in any development program is Human-Centred or User-Centred Design. For a process that has sounds rather complicated, it’s actually based on some very simple and low-tech ideas. To describe HCD, let’s break the development process into 3 distinct stages:-

1. Understand the user’s requirements for the product.

In particular try to gain an understanding of the user’s pain point or difficulties.

2. Innovate and design a solution for the user’s product requirements.

3. Test and evaluate the solution with users.

Take the lessons learned and go back to stage 1.

Repeat steps 1, 2 and 3 as required. Any development is a compromise and engineering judgement needs to be used to decide when the improvements are no longer worth the effort of repeating the cycle. HCD techniques come into play mainly in stages 2 and 3 giving the solution developers a set of techniques for presenting and evaluating solutions with users as well as techniques for prioritising evaluation results.

I opened this post by saying that designing for ease of use is not a simple exercise. Although there are only 3 steps listed above they all involve a lot of work, usually over a significant period of time. Adopting HCD techniques can help you increase the chances of a successful development. I’ll elaborate on the HCD techniques in a follow-up post.

Apple Mac: How to Take a Screenshot

One nifty feature I’ve found with my new Apple Mac Mini is that taking screenshots is real easy. If you want to capture an image of a portion of the desktop, simply type the key sequence:

cmd-shift-4

i.e. press down both the cmd key and the shift key then press the 4 key at the same time.

The Mac then displays cursors that you can drag with the mouse to grab any portion of the screen you like – press the left mouse button to begin capture then move the mouse to encompass the desired are before releasing the left mouse button to complete the capture. The image is then automatically saved as a PNG file on the desktop.

After the image is saved onto the desktop, double-clicking the image with the mouse displays the image in the Preview tool. The Preview tool contains a number of handy features, e.g. the Tools menu lets you resize the image and the File menu contains options to export the image in different formats, e.g. as a .JPG file.

Apple Mac: Enabling the Mouse Right-Click

Having recently bought an Apple Mac, I’d begun working my way through tutorials on how to use XCode, Apple’s IDE for iPhone/ iPad development. Coming from a PC, I had a learning curve on how to use some of the basic Mac features. I’m not saying the Mac is better or worse than a PC, just different. It’s always good to learn something new!

One thing that did confuse me for a while was that the tutorials I was following required me to right-click the mouse on certain items to bring up a context menu. Unfortunately this simply didn’t work, I clicked on the right side of the mouse but no menu appeared. My confusion was increased as the mouse I’d bought (for over £30!) didn’t appear to have separate left and right buttons. Eventually I figured out that the mouse was configurable and that I had to enable use of the right mouse button feature as it wasn’t enabled by default. To enable the right mouse, I had to open the System Preferences by clicking on this button:

Apple-Mac-System-Preferencesthen navigate to the Mouse preferences under the Hardware section in the preferences. Finally I had to enable the Secondary button for the right mouse button as shown in this picture:

mac-right-mouse-settings

After doing this, I could right-click the mouse and bring up the context menu, just like on a PC.

Hands Up Who Likes Business Planning?

business-planning

Do you find you don’t have time to do any business planning?  Are you too busy getting on with the actual business side of things, the things that get the income coming in? Or perhaps more honestly, you think that “planning” or “strategy” is:-

a) boring as heck?
b) a mystery?
c) irrelevant?

So What Is Business Planning?

START-UP PLANNING

Well there’s the start-up business plan which is your tool for setting out your initial goals and how you will achieve them. It takes a detailed look at your proposed business idea and how likely it is to succeed. It includes financial forecasts covering what money you see coming in and going out of your business. It usually covers a 3-5 year period. This video explains more about it – https://www.gov.uk/write-business-plan

ONGOING MONITORING & PLANNING

You’d be forgiven for thinking that “business planning” was only something to do when starting up rather than running a business. If you google “business planning” for example, a high proportion of articles will be about start-ups and creating you first  business plan.
But once you’re in business, it pays to refer back regularly to your original plan to see whether things are going according to plan, financially and in relation to your other goals.

If you aware that things are not going to plan, you can do what is necessary to address any issues before they become critical. Also unexpected changes can be positive developments. You may find a market for your audience that you hadn’t been aware of before. If you take the time to look at how these changes fit in with your overall goals, it will help you keep focussed.
In addition to regular monitoring of your cashflow, you might once a year, review your goals & make plans in the areas of finance, sales, marketing, HR, for example.

Setting measurable objectives for the year ahead makes it easier to monitor your performance. So rather than vague goals such as “increase sales” or “raise company profile” set specific and realistic targets such as % increase in sales, 3 articles in local paper, x number of facebook fans, reduce overdraft by x amount.

I’ve talked to several people who run small businesses over the years and I’m always amazed that planning is often so far down on their agenda or sometimes not on their radar at all!

If you applied that logic elsewhere it would seem a bit odd. For example, you don’t step out of your front door in the morning without an idea of where it is you’re going.

A while back I was working as Communications Officer for an organisation and had been asked to produce a Communications Strategy. I was talking to my boss one day about the importance of strategy and said “if you don’t have a strategy, you’re in the dark, a bit like trying to pack for a holiday without knowing where you’re going “. He said “Oh! I’d happily go with an empty suitcase!”.
That taught me a valuable lesson. To remember that not everyone has the same outlook on life, the same values or personality. Luckily for me, I like planning, I’m more of thinker than do-er, so it’s not a chore for me to spend time analysing and committing ideas to paper. But if you’re a do-er I can quite understand that you may well prefer to watch paint dry than sit down and write business forecasts.

If for whatever reason, you find yourself saying “no” to the task of business planning, at least be aware of how vulnerable that makes your business.  Lack of planning is often cited as one of the reasons for small business failure.  There’s plenty of guidance on planning out there. Here are a few sources of information to start you off:

http://www.guardian.co.uk/small-business-network/2012/jul/06/business-plan-writing-tips

For further business tips, check out our blog post on simple accounting tips.