Tuesday, 27 January 2015

Deleting svn files and directories, Mac OSX

I recently inherited a project that used to be in svn and is now thankfully in git. Unfortunately all the old svn files were still hanging around. To remove them I did this from the root of the project
find . -name .svn  -type d -print0 |xargs -0 rm -rf

Wednesday, 7 January 2015

Entity Framework - Unable to update EntitySet - it has a DefiningQuery and no element exists to support the current operation.

I had this error when working on an older .Net site yesterday with EF4. It seems that the db table wasn't setup with a primary key which apparently makes EF see it as a view. Looking at the XML in the .edmx file revealed this for my table:

<entityset Name="SpecialFeatures" EntityType="EB.Store.SpecialFeatures" store:Type="Tables" store:Schema="dbo" store:Name="SpecialFeatures">
            <definingquery>SELECT 
      [SpecialFeatures].[Id] AS [Id], 
      [SpecialFeatures].[ProductDetailIcon] AS [ProductDetailIcon], 
      [SpecialFeatures].[SearchResultsIcon] AS [SearchResultsIcon], 
      [SpecialFeatures].[Name] AS [Name]
      FROM [dbo].[SpecialFeatures] AS [SpecialFeatures]
</definingquery>
          </entityset>
To overcome this problem I performed the following surgery on the db and xml:
  1. Add a primary key to the db table in SSMS
  2. Open edmx file in text editor
  3. Locate the entity in the edmx:StorageModels element
  4. Remove the DefiningQuery entirely
  5. Rename the store:Schema="dbo" to Schema="dbo"
  6. Remove the store:Name property