Click here to Skip to main content
15,881,757 members
Articles / Programming Languages / C#

Comparing Transparent Lazy Loading between NHibernate and Entity Framework

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
14 Jan 2012CPOL7 min read 35.7K   920   23  
In this article, I will explain what transparent lazy loading is and how it's implemented in NHibernate and Entity Framework.
  • LazyLoadingEntityFramework_src.zip
  • CreatTables_sql.zip
  • LazyLoadingNHibernate_src.zip
    • LazyLoadingNHibernate
      • Demo.Tests
      • Demo
      • LazyLoadingNHibernate.sln
      • LazyLoadingNHibernate.vsmdi
      • Library
        • Iesi.Collections.dll
        • NHibernate.dll
      • Local.testsettings
      • TestResults
        • Henry_LAPTOP 2012-01-13 20_27_04.trx
        • Henry_LAPTOP 2012-01-13 20_29_28.trx
        • Henry_LAPTOP 2012-01-13 20_31_42.trx
        • Henry_LAPTOP 2012-01-13 20_32_42.trx
        • Henry_LAPTOP 2012-01-13 20_36_10.trx
        • Henry_LAPTOP 2012-01-13 20_36_10
          • In
            • LAPTOP
          • Out
            • AgentRestart.dat
        • Henry_LAPTOP 2012-01-13 20_37_05.trx
        • Henry_LAPTOP 2012-01-13 20_37_19.trx
        • Henry_LAPTOP 2012-01-13 20_40_25.trx
        • Henry_LAPTOP 2012-01-13 20_43_37.trx
        • Henry_LAPTOP 2012-01-13 20_43_37
          • In
            • LAPTOP
          • Out
            • AgentRestart.dat
        • Henry_LAPTOP 2012-01-13 20_46_24.trx
        • Henry_LAPTOP 2012-01-13 20_46_24
          • In
            • LAPTOP
          • Out
            • AgentRestart.dat
        • Henry_LAPTOP 2012-01-13 20_50_33.trx
        • Henry_LAPTOP 2012-01-13 20_50_33
          • In
            • LAPTOP
          • Out
            • AgentRestart.dat
        • Henry_LAPTOP 2012-01-13 20_50_58.trx
        • Henry_LAPTOP 2012-01-13 20_50_58
          • In
            • LAPTOP
          • Out
            • AgentRestart.dat
        • Henry_LAPTOP 2012-01-13 20_56_53.trx
        • Henry_LAPTOP 2012-01-13 20_57_27.trx
        • Henry_LAPTOP 2012-01-13 20_57_57.trx
        • Henry_LAPTOP 2012-01-13 20_58_28.trx
        • Henry_LAPTOP 2012-01-13 20_58_28
          • In
            • LAPTOP
          • Out
            • AgentRestart.dat
        • Henry_LAPTOP 2012-01-13 21_01_34.trx
        • Henry_LAPTOP 2012-01-13 21_01_42.trx
        • Henry_LAPTOP 2012-01-13 21_02_01.trx
        • Henry_LAPTOP 2012-01-13 21_02_01
          • In
            • LAPTOP
          • Out
            • AgentRestart.dat
      • TraceAndTestImpact.testsettings
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>
    </ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{3C9863BA-B612-4880-BA0F-FAF2830D6DB9}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Demo.Tests</RootNamespace>
    <AssemblyName>Demo.Tests</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Iesi.Collections">
      <HintPath>..\Library\Iesi.Collections.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
    <Reference Include="NHibernate">
      <HintPath>..\Library\NHibernate.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Core">
      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
      <Visible>False</Visible>
    </CodeAnalysisDependentAssemblyPaths>
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="DemoTest.cs" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Demo\Demo.csproj">
      <Project>{419BEACB-79CD-4B94-A71A-998FDDD2291D}</Project>
      <Name>Demo</Name>
    </ProjectReference>
  </ItemGroup>
  <ItemGroup>
    <Content Include="hibernate.cfg.xml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Senior Software Developer from New Jersey, USA

Have 15+ years experience on enterprise application development with various technologies.

Comments and Discussions