﻿<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>All things .Net</title>
    <description>As all developers I frequently find myself researching items I've figured out before, so I've decided to add them to this blog to aid my memory. At the same time I hope it helps others in finding answers to their technical problems.</description>
    <link>http://www.insidelogic.nl/Blog/tabid/146/BlogId/2/language/en-US/Default.aspx</link>
    <language>nl-NL</language>
    <managingEditor>dimitri@insidelogic.nl</managingEditor>
    <webMaster>dimitri@insidelogic.nl</webMaster>
    <pubDate>Sun, 20 May 2012 13:28:17 GMT</pubDate>
    <lastBuildDate>Sun, 20 May 2012 13:28:17 GMT</lastBuildDate>
    <docs>http://backend.userland.com/rss</docs>
    <generator>Blog RSS Generator Version 3.5.1.19887</generator>
    <item>
      <title>Session, querystring and form variables in LINQ</title>
      <description>&lt;p&gt;I ran into an annoying issue today while trying to select some records using LINQ to Entities. The code was simple:&lt;/p&gt;
&lt;pre class="brush: vb;" title="code"&gt;
Dim ppl = From c In ctx.People Where c.AddedBy = Request("e") Select c&lt;/pre&gt;
&lt;p&gt; but i kept getting the following error:&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #808080"&gt;&lt;em&gt;"LINQ to Entities does not recognize the method 'System.String get_Item(System.String)' method, and this method cannot be translated into a store expression"&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The reason for this lies with the Request variables which i'm using to get the email address from the querystring. Bob Powell found the solution - it seems like the order of how expressions are evaluated has a problem, and that the querystring value is not evaluated at the time that the select statement is built, hence the runtime cannot evaluate the value coming from the querystring (or session/form variables).&lt;/p&gt;
&lt;p&gt;The solution is simple, simply create a variable to contain the request variable and use that in the query:&lt;/p&gt;
&lt;pre class="brush: vb;" title="code"&gt;
Dim email As String = Request("e")
Dim ppl = From c In ctx.People Where c.AddedBy = email Select c&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;You can read Bob's post here:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bobpowelldotnet.blogspot.com/2009_01_01_archive.html"&gt;http://bobpowelldotnet.blogspot.com/2009_01_01_archive.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Dimitri&lt;/p&gt;</description>
      <link>http://www.insidelogic.nl/Blog/tabid/146/EntryId/6/Session-querystring-and-form-variables-in-LINQ.aspx</link>
      <author>dimitri@insidelogic.nl</author>
      <comments>http://www.insidelogic.nl/Blog/tabid/146/EntryId/6/Session-querystring-and-form-variables-in-LINQ.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.insidelogic.nl/Blog/tabid/146/EntryId/6/Session-querystring-and-form-variables-in-LINQ.aspx</guid>
      <pubDate>Thu, 20 Aug 2009 11:41:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.insidelogic.nl/DesktopModules/Blog/Trackback.aspx?id=6</trackback:ping>
    </item>
    <item>
      <title>'localhost' no longer working in Visual Studio?</title>
      <description>&lt;p&gt;For some time my Visual Studio has had a problem displaying web pages when debugging, and if you've been keeping your windows updates running, most likely you've got the same problem.&lt;/p&gt;
&lt;p&gt;This happens when you're using the built-in web server and Visual Studio uses http:localhost:
&lt;port&gt;&lt;/port&gt;
/site. In fact, any reference to localhost fails to find the page you're looking for.&lt;/p&gt;
&lt;p&gt;Turns out that an update to Windows Defender messed around with the hosts file which lists host names and matches them to predefined IP addresses. This file resides in C:\Windows\System32\drivers\etc (on Vista at least) and you'll find the following line inside:&lt;/p&gt;
&lt;pre class="brush: vb;gutter: false; toolbar: false; " title="code"&gt;
::1             localhost&lt;/pre&gt;
&lt;p&gt;It should be:&lt;/p&gt;
&lt;pre class="brush: vb;gutter: false; toolbar: false; " title="code"&gt;
127.0.0.1 localhost&lt;/pre&gt;
&lt;p&gt;Problem solved!&lt;/p&gt;</description>
      <link>http://www.insidelogic.nl/Blog/tabid/146/EntryId/5/localhost-no-longer-working-in-Visual-Studio.aspx</link>
      <author>dimitri@insidelogic.nl</author>
      <comments>http://www.insidelogic.nl/Blog/tabid/146/EntryId/5/localhost-no-longer-working-in-Visual-Studio.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.insidelogic.nl/Blog/tabid/146/EntryId/5/localhost-no-longer-working-in-Visual-Studio.aspx</guid>
      <pubDate>Mon, 06 Apr 2009 17:12:00 GMT</pubDate>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://www.insidelogic.nl/DesktopModules/Blog/Trackback.aspx?id=5</trackback:ping>
    </item>
    <item>
      <title>Create DTO (Data transfer objects) from an Entity Framework edmx file</title>
      <description>&lt;p&gt;This post will show you a simple way to generate DTO's (Data transfer objects) from your Entity Framework diagram by reading the XML file that is generated (.edmx) and creating DTO classes based on your diagram.&lt;/p&gt;
&lt;p&gt;&lt;img border="1" hspace="2" alt="" vspace="2" align="left" width="348" height="246" src="/main/Portals/0/Insidelogic/Blog/blog_sample_entitydiagram.png" /&gt;Data transfer objects are used to pass data to consumers of your web/wcf services, to prevent your data layer objects from being exposed to a third party.&lt;/p&gt;
&lt;p&gt;The Entity Framework takes out almost all the work of creating an effective data layer in a .Net application. It's easy to use and great for most applications, but the generated objects should be used internally to access your data store, and should never be sent out to a third party.&lt;/p&gt;
&lt;p&gt;On the left is a sample entity diagram showing a customer entity with related addresses. This sample has few entities with few properties, and you could easily create DTO objects in code which include only the properties you'd like to expose, but if you have to do this for a large object model then you can spend hours on this task. Worse still, every time you modify your model, you need to modify your DTO classes.&lt;/p&gt;
&lt;p&gt;To automate this task we can use the XML file which is generated by the Entity Diagram designer - the .edmx file. This file contains all the mapping information which maps your database objects to your generated entities, include database types and CLR types. We simply need to read the CLR entity descriptions in this file, and generate the DTO code containing the same classes and properties. From there you can edit the DTO classes to exclude certain entities and properties.&lt;/p&gt;
&lt;p&gt;The XML section we're interested in is shown here:&lt;/p&gt;
&lt;p&gt;&lt;img alt="edmx code" width="730" height="400" src="/main/Portals/0/Insidelogic/Blog/blog_sample_edmx.png" /&gt; &lt;/p&gt;
&lt;p&gt;&lt;img alt="DTO Generator" align="right" width="298" height="297" src="/main/Portals/0/Insidelogic/Blog/blog_sample_DTO_screen.png" /&gt;&lt;/p&gt;
&lt;p&gt;The window used to generate your DTO from allows you to select an edmx file, provide a namespace and generate the code.&lt;/p&gt;
&lt;p&gt;No fancy reflection being used here, I simply build up the code in a string and output it in the large text box to copy and paste to your project.&lt;/p&gt;
&lt;p&gt;I'm generating VB code here, but the application can of course easily be modified to generate C# code.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;The generated code looks as follows:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="background-color: white; height: 400px; overflow: auto"&gt;
&lt;pre class="brush: vb;" title="code"&gt;
Namespace DTO

    Public Class Addresses

        Private _ID As Int32
        Private _Addres1 As String
        Private _Addres2 As String
        Private _Addres3 As String
        Private _Addres4 As String
        Private _StreetNumber As String
        Private _PostCode As String
        Private _City As String
        Private _CountryID As Nullable(Of Int32)

        Public Property ID() As Int32
            Get
                Return _ID
            End Get
            Set(ByVal value As Int32)
                _ID = value
            End Set
        End Property

        Public Property Addres1() As String
            Get
                Return _Addres1
            End Get
            Set(ByVal value As String)
                _Addres1 = value
            End Set
        End Property

        Public Property Addres2() As String
            Get
                Return _Addres2
            End Get
            Set(ByVal value As String)
                _Addres2 = value
            End Set
        End Property

        Public Property Addres3() As String
            Get
                Return _Addres3
            End Get
            Set(ByVal value As String)
                _Addres3 = value
            End Set
        End Property

        Public Property Addres4() As String
            Get
                Return _Addres4
            End Get
            Set(ByVal value As String)
                _Addres4 = value
            End Set
        End Property

        Public Property StreetNumber() As String
            Get
                Return _StreetNumber
            End Get
            Set(ByVal value As String)
                _StreetNumber = value
            End Set
        End Property

        Public Property PostCode() As String
            Get
                Return _PostCode
            End Get
            Set(ByVal value As String)
                _PostCode = value
            End Set
        End Property

        Public Property City() As String
            Get
                Return _City
            End Get
            Set(ByVal value As String)
                _City = value
            End Set
        End Property

        Public Property CountryID() As Nullable(Of Int32)
            Get
                Return _CountryID
            End Get
            Set(ByVal value As Nullable(Of Int32))
                _CountryID = value
            End Set
        End Property

    End Class


    Public Class Customers

        Private _ID As Int32
        Private _Name As String
        Private _VAT_number As String
        Private _Rate As Nullable(Of Decimal)

        Public Property ID() As Int32
            Get
                Return _ID
            End Get
            Set(ByVal value As Int32)
                _ID = value
            End Set
        End Property

        Public Property Name() As String
            Get
                Return _Name
            End Get
            Set(ByVal value As String)
                _Name = value
            End Set
        End Property

        Public Property VAT_number() As String
            Get
                Return _VAT_number
            End Get
            Set(ByVal value As String)
                _VAT_number = value
            End Set
        End Property

        Public Property Rate() As Nullable(Of Decimal)
            Get
                Return _Rate
            End Get
            Set(ByVal value As Nullable(Of Decimal))
                _Rate = value
            End Set
        End Property

    End Class


End Namespace
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.insidelogic.nl/main/LinkClick.aspx?fileticket=hkn7jLAh6YQ%3d&amp;tabid=146&amp;language=en-US"&gt;Download the source code&lt;/a&gt;&lt;/p&gt;</description>
      <link>http://www.insidelogic.nl/Blog/tabid/146/EntryId/4/Create-DTO-Data-transfer-objects-from-an-Entity-Framework-edmx-file.aspx</link>
      <author>dimitri@insidelogic.nl</author>
      <comments>http://www.insidelogic.nl/Blog/tabid/146/EntryId/4/Create-DTO-Data-transfer-objects-from-an-Entity-Framework-edmx-file.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.insidelogic.nl/Blog/tabid/146/EntryId/4/Create-DTO-Data-transfer-objects-from-an-Entity-Framework-edmx-file.aspx</guid>
      <pubDate>Fri, 03 Apr 2009 03:15:19 GMT</pubDate>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://www.insidelogic.nl/DesktopModules/Blog/Trackback.aspx?id=4</trackback:ping>
    </item>
    <item>
      <title>To kick off...</title>
      <description>&lt;p&gt;Welcome to my blog page.&lt;/p&gt;
&lt;p&gt;Since I started developing many many years ago as a hobby I've seen many platforms and technologies come and go. In my time I've tried my hand at Pascal, Cobol, C++, various web scripting technologies and creating CGI scripts in the early days, VB, ASP, and more!&lt;/p&gt;
&lt;p&gt;And then I finally found .NET.&lt;/p&gt;
&lt;p&gt;I had been following the Java route for some time when I decided to move to .Net when framework 1.1 came along, and although it had it's hiccups, it's support for multiple languages on top of a single framework seemed like a miracle to me.&lt;/p&gt;
&lt;p&gt;When Framework 2.0 came along, I found my departure from Java to be completely justified and started delving deeper into the functionality offered by the framework. Nowadays I spend a great deal of my time keeping up to date on the latest coming out of the .Net stable, and I hope to share my discoveries with you here. Questions are welcome, and although I will not be able to answer all of them, I'll allways respond, at least privately.&lt;/p&gt;</description>
      <link>http://www.insidelogic.nl/Blog/tabid/146/EntryId/3/To-kick-off.aspx</link>
      <author>dimitri@insidelogic.nl</author>
      <comments>http://www.insidelogic.nl/Blog/tabid/146/EntryId/3/To-kick-off.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.insidelogic.nl/Blog/tabid/146/EntryId/3/To-kick-off.aspx</guid>
      <pubDate>Fri, 13 Mar 2009 18:32:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.insidelogic.nl/DesktopModules/Blog/Trackback.aspx?id=3</trackback:ping>
    </item>
  </channel>
</rss>
