Thursday, 22 September 2011

EF Mapping with POCO Errors

If you ever receive the following error messaging containing this wording “Mapping and metadata information could not be found for EntityType”, it is a rather anonymous message saying that in the Model folder of the EF mappings in the .edmx file, something has gone wrong in the mappings of the XML somewhere.

For anyone else dealing with the error,  it's clearly stating the likely scenarios which I've found that cause this (extremely unhelpful) error:

  • Misspelled properties (case-sensitive!) This is the most likely problem, if somewhere in your model fields/attributes are missing to the conceptual model of your database, Visual Studio will complain like nobody’s business, make sure all fields/attributes/variables right down to the types match correctly. E.g.

    <EntityType Name="test">
      <Key>
        <PropertyRef Name="testID" />
        <PropertyRef Name="secondtestID" />
      </Key>
      <Property Type="String" Name="test" Nullable="false" MaxLength="16" FixedLength="true" Unicode="false" />
      <Property Type="Int32" Name="secondtestID" Nullable="false" />
      <Property Type="String" Name="CLI" MaxLength="25" FixedLength="true" Unicode="false" />
      <Property Type="DateTime" Name="ReceivedTime" />
      <Property Type="String" Name="testparam" MaxLength="100" FixedLength="true" Unicode="false" />
      <Property Type="Boolean" Name="testbool" />
    </EntityType>

    This has got to match with the variables in the model class of your web service.

  • Properties missing in the POCO class. (You need to write everything down correctly!) This also includes things lime Nullable=”false” for keys, you need to include this otherwise it won’t work.
  • Type mismatches between the POCO and entity-type (e.g., int 32 instead of long)
  • Enums in the POCO (EF doesn't support enums right now, so don’t include them)

Friday, 16 September 2011

DataBinding in WP7–The Quick and Easy Way

Here is something I found for those who wish to perform databinding on a  List Box using ItemsSource using static data the quick and easy way!

I started by added a static reference to the MainViewModel in the App class of App.xaml.cs

 private static MainViewModel viewModel = null;

public static MainViewModel ViewModel
{
get
{
// Delay creation of the view model until necessary
if (viewModel == null)
viewModel = new MainViewModel();
return viewModel;
}
}


My two lists in the MainViewModel class of MainViewModel.cs looked like this:



 public MainViewModel()
{
// Insert code required on object creation below this point
Items1 = new ObservableCollection<ItemViewModel>() {
new ItemViewModel() { LineOne = "runtime one", LineTwo = "Maecenas praesent accumsan bibendum", LineThree = "Facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu", },
new ItemViewModel() { LineOne = "runtime two", LineTwo = "Dictumst eleifend facilisi faucibus", LineThree = "Suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus", },
new ItemViewModel() { LineOne = "runtime three", LineTwo = "Habitant inceptos interdum lobortis", LineThree = "Habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent", },
};

Items2 = new ObservableCollection<ItemViewModel>() {
new ItemViewModel() { LineOne = "runtime one", LineTwo = "Maecenas praesent accumsan bibendum", LineThree = "Facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu", },
new ItemViewModel() { LineOne = "runtime two", LineTwo = "Dictumst eleifend facilisi faucibus", LineThree = "Suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus", },
};

}

public ObservableCollection<ItemViewModel> Items1 { get; private set; }

public ObservableCollection<ItemViewModel> Items2 { get; private set; }


Now I changed the initialisation of DataContext in MainPage.xaml.cs to reference the static object



  if (DataContext == null)
DataContext = App.ViewModel;


Removed the direct reference to the Items1 list in MainPage.xaml so it only had the binding



  <ListBox x:Name="ListBoxOne" ItemsSource="{Binding}" MouseLeftButtonUp="ListBoxOne_MouseLeftButtonUp" Style="{StaticResource PhoneListBox}">


And now I can use my conditions check to set the ItemsSource using the following code in MainPage.xaml.cs



  ListBoxOne.ItemsSource = App.ViewModel.Items2;

Thursday, 15 September 2011

How to install Microsoft SQL Server Management Studio on desktop

A common dilemma is to see that you have MS SQL Server 2008 installed but not the Microsoft SQL Server Management Studio on your PC, to do it go to : -

http://www.microsoft.com/download/en/details.aspx?id=7593

This link installs the Express edition which does essentially everything you need associated with MS Server 2008, as it says its an integrated environment for accessing, configuring, managing, administering, and developing all components of SQL Server 2008!

sqlserver2008

What I found also is that the installation file wouldn’t install it automatically, you have to select New Install on the SQL Server 2008 Setup, and manually tick the one and only (yes one) shared feature which is Management Tools – Basic to install the Microsoft SQL Server Management Studio on your PC Desktop. Wait for 10 minutes. Voila!

Also if you are programmer, you want to test certain database files for local use in Microsoft Visual Studio 2010, and that means that you want to be able to attach the database on another server (well locally on Visual Studio 2010), then this is what you can do:

  1. Detach the database (right click the database and click Detach)
  2. Copy the mdf and ldf files to your backup location
  3. Attach the database (right click Databases and click Attach)

Wednesday, 14 September 2011

More information on checking if an element exists in JQuery

The simplest mistake sometimes costs several hours of debugging. One of these is checking if the target exists before trying to apply some changes to/using it.

How to check if element in DOM exists, i.e. if the selector $(‘.some_class’) is not empty?

The simplest:

if ($('.some_class')) {

//some action

}

will not work!

The correct condition uses the .length function:

if ($('.some_class').length > 0) {

//some action

}

Note no brackets after .length.

How to check if JavaScript object’s property exists?

This is tricky, as there are two types of properties: own properties and prototype properties. Not going into details, we can assume, that own properties are the one that are for example serialized by JSON, and prototype properties are the one that can be empty or not, but are given in the object’s definition.

So, in most cases you want to check if the own property exists for the given object. This can be obtained using the hasOwnProperty() method:

if (the_object.hasOwnProperty("name)) {

//some action

}

If you only want to check whether there is the prototype property, you may use in operator to determine the existence of the property:

if ("name" in the_object)) {

//some action

}

Tuesday, 13 September 2011

How to Swipe gesture on JQuery Mobile}

 

Here is the code for how to do swipe gesture in JQuery Mobile, here it checks the body tag, and sets a “live” event to detect the swipe gesture, and shows an alert.

  $("body").live('swipe', function() {
         alert("swiped");

}

Monday, 12 September 2011

Bug fixed for Samsung Galaxy SII

For some reason when viewing a dialog page for JQuery Mobile using Android 2.22 on Samsung Galaxy SII, if you close the dialog box when opening from main page, such that it goes back to the main page again, and click a submit button, on the application I am writing it goes back to the dialog page which is not what I wanted. That is a real surprise considering its the latest Android device, and hasn’t been thoroughly tested on the latest version with JQuery Mobile. The long fix is to manually remove the submit button, and manually append the same button with the ID, and with the binding click event from the main JS file, which means copying the right functions.

Monday, 5 September 2011

Sorted out IIS 7.0 Issues and fixed most of AtomSite blog for mashupweb.co.uk

Finally, on Friday and today I have fixed at what it seems a simple error as to why I couldn’t log in to IIS 7.0, having trying to reinstall AtomSite on Web Platform Installer which is the supposed official program wizard from Microsoft to install new programs for IIS.

However, the same error message kept on appearing as shown: -

webplatforminstaller3

The message had read Filename: \\?\C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config

Line Number 141

Error: Configuration section not allowed in a <location> tag.

I had even attempted to reinstall the IIS 7.0 components as shown in the screenshot below, by removing the roles for Web Server, but to no rprevial, the same error had shown up again the following day!

DasBlog2

After an hour the next day of baffling how to solve it but trying to install new programs like Wordpress, the same error had shown. The fact was that extra tags had been added in the machine.config on that line which was a fatal mistake, it had something to do with allowpermissions and allowoverrides added into the line. Fact: don’t tamper with the file at all!

IIS 7.0 ran perfectly after that without having to ask you to log in.

On some good fortune as well, I solve part of the problem as to why AtomSite wasn’t working properly with the blog entry links, it had something to do with the the with the theme settings in Administration, so switching all to Blue setting in the same theme for www , blog, and all other entries made it work.

Friday, 26 August 2011

Rob Miles JumpStart Training on Windows Phone 7

Yesterday, I had the privilege to watch a bit of the Jumpstart training on Windows Phone 7 with Rob Miles and Andy Wigley after work, even though it was two hours,.

I did gets some great tips on creating great applications especially on advice when creating a “light version” of an application rather than the trail mode as it entices them to purchase the full application more via a link rather than being put off by the word “trial” with its limited features that it imposes.

Other tips were to make full use of the application submissions as a dedicated app published reviewer from Microsoft reviews and takes note of if the application is deemed worthy to be published, so only 100 application attempts for publishing are free, after you need to pay for publishing your app, this is for the free version of your application that is.

Here is some screenshots made from the online event.

robmiles7

robmiles8