Skip to content

Commit 8be8a53

Browse files
committed
Adding F# sample project Ensure that we can handle non writable Id properties
1 parent 4509e37 commit 8be8a53

File tree

6 files changed

+113
-4
lines changed

6 files changed

+113
-4
lines changed

Raven.Client.Tests/Bugs/Etag.cs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public void WhenSaving_ThenGetsEtag()
1919
session.SaveChanges();
2020

2121
var metadata = session.GetMetadataFor(foo);
22-
// TODO: THIS FAILS
2322
Assert.NotNull(metadata.Value<string>("@etag"));
2423
}
2524

Raven.Client/Document/InMemoryDocumentSessionOperations.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ protected object ConvertToEntity<T>(string id, JObject documentFound, JObject me
189189
#endif
190190
}
191191
var identityProperty = documentStore.Conventions.GetIdentityProperty(entity.GetType());
192-
if (identityProperty != null)
192+
if (identityProperty != null && identityProperty.CanWrite)
193193
identityProperty.SetValue(entity, id, null);
194194
return entity;
195195
}
@@ -226,7 +226,7 @@ public void Store(object entity)
226226
// Generate the key up front
227227
id = Conventions.GenerateDocumentKey(entity);
228228

229-
if (id != null && identityProperty != null)
229+
if (id != null && identityProperty != null && identityProperty.CanWrite)
230230
{
231231
// And store it so the client has access to to it
232232
identityProperty.SetValue(entity, id, null);
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Learn more about F# at http://fsharp.net
2+
3+
4+
type Movie =
5+
{
6+
Id:string
7+
Title:string
8+
Summary:string
9+
}
10+
11+
let create() =
12+
let store = new Raven.Client.Document.DocumentStore()
13+
store.Url <- "http://localhost:8080/"
14+
store.Initialize() |> ignore
15+
16+
use session = store.OpenSession()
17+
let x = {Id = null; Title ="Terminator 2"; Summary ="It was the end of the world"}
18+
session.Store(x)
19+
session.SaveChanges()
20+
21+
let read() =
22+
let store = new Raven.Client.Document.DocumentStore()
23+
store.Url <- "http://localhost:8080/"
24+
store.Initialize() |> ignore
25+
26+
use session = store.OpenSession()
27+
let m = session.Load<Movie>("movies/1")
28+
System.Console.WriteLine("{0} {1} {2}", m.Id, m.Title, m.Summary)
29+
30+
31+
create()
32+
read()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{33a1012f-409e-4cb4-97f3-f25e27ba7b61}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<RootNamespace>Raven.Sample.FSharp</RootNamespace>
11+
<AssemblyName>Raven.Sample.FSharp</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
14+
<Name>Raven.Sample.FSharp</Name>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<Tailcalls>false</Tailcalls>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<WarningLevel>3</WarningLevel>
24+
<PlatformTarget>x86</PlatformTarget>
25+
<DocumentationFile>bin\Debug\Raven.Sample.FSharp.XML</DocumentationFile>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<Tailcalls>true</Tailcalls>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<WarningLevel>3</WarningLevel>
34+
<PlatformTarget>x86</PlatformTarget>
35+
<DocumentationFile>bin\Release\Raven.Sample.FSharp.XML</DocumentationFile>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="mscorlib" />
39+
<Reference Include="FSharp.Core" />
40+
<Reference Include="Newtonsoft.Json">
41+
<HintPath>..\..\SharedLibs\Newtonsoft.Json.dll</HintPath>
42+
</Reference>
43+
<Reference Include="System" />
44+
<Reference Include="System.Core" />
45+
<Reference Include="System.Numerics" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Compile Include="Program.fs" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<ProjectReference Include="..\..\Raven.Client.Lightweight\Raven.Client.Lightweight.csproj">
52+
<Name>Raven.Client.Lightweight</Name>
53+
<Project>{4e087ecb-e7ca-4891-ac3c-3c76702715b6}</Project>
54+
<Private>True</Private>
55+
</ProjectReference>
56+
</ItemGroup>
57+
<Import Project="$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets" Condition="!Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
58+
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
59+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
60+
Other similar extension points exist, see Microsoft.Common.targets.
61+
<Target Name="BeforeBuild">
62+
</Target>
63+
<Target Name="AfterBuild">
64+
</Target>
65+
-->
66+
</Project>

Samples/Raven.Samples.sln

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raven.Server", "..\Raven.Se
2727
EndProject
2828
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raven.Storage.Esent", "..\Raven.Storage.Esent\Raven.Storage.Esent.csproj", "{9DEE8674-D0CD-430D-BD9B-6CD95F3CAB22}"
2929
EndProject
30+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Raven.Sample.FSharp", "Raven.Sample.FSharp\Raven.Sample.FSharp.fsproj", "{33A1012F-409E-4CB4-97F3-F25E27BA7B61}"
31+
EndProject
3032
Global
3133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3234
Debug|Any CPU = Debug|Any CPU
@@ -157,6 +159,16 @@ Global
157159
{9DEE8674-D0CD-430D-BD9B-6CD95F3CAB22}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
158160
{9DEE8674-D0CD-430D-BD9B-6CD95F3CAB22}.Release|Mixed Platforms.Build.0 = Release|Any CPU
159161
{9DEE8674-D0CD-430D-BD9B-6CD95F3CAB22}.Release|x86.ActiveCfg = Release|Any CPU
162+
{33A1012F-409E-4CB4-97F3-F25E27BA7B61}.Debug|Any CPU.ActiveCfg = Debug|x86
163+
{33A1012F-409E-4CB4-97F3-F25E27BA7B61}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
164+
{33A1012F-409E-4CB4-97F3-F25E27BA7B61}.Debug|Mixed Platforms.Build.0 = Debug|x86
165+
{33A1012F-409E-4CB4-97F3-F25E27BA7B61}.Debug|x86.ActiveCfg = Debug|x86
166+
{33A1012F-409E-4CB4-97F3-F25E27BA7B61}.Debug|x86.Build.0 = Debug|x86
167+
{33A1012F-409E-4CB4-97F3-F25E27BA7B61}.Release|Any CPU.ActiveCfg = Release|x86
168+
{33A1012F-409E-4CB4-97F3-F25E27BA7B61}.Release|Mixed Platforms.ActiveCfg = Release|x86
169+
{33A1012F-409E-4CB4-97F3-F25E27BA7B61}.Release|Mixed Platforms.Build.0 = Release|x86
170+
{33A1012F-409E-4CB4-97F3-F25E27BA7B61}.Release|x86.ActiveCfg = Release|x86
171+
{33A1012F-409E-4CB4-97F3-F25E27BA7B61}.Release|x86.Build.0 = Release|x86
160172
EndGlobalSection
161173
GlobalSection(SolutionProperties) = preSolution
162174
HideSolutionNode = FALSE

default.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ task DoRelease -depends Compile {
308308
cp $build_dir\Raven.Database.dll $build_dir\Output\Server
309309
cp $build_dir\Raven.Storage.Managed.dll $build_dir\Output\Server
310310
cp $build_dir\Raven.Storage.Esent.dll $build_dir\Output\Server
311-
cp $base_dir\DefaultConfigs\RavenDb.exe.config $build_dir\Output\Server\RavenDb.exe.config
311+
cp $base_dir\DefaultConfigs\RavenDb.exe.config $build_dir\Output\Server\Raven.Server.exe.config
312312

313313
cp $base_dir\license.txt $build_dir\Output\license.txt
314314
cp $base_dir\readme.txt $build_dir\Output\readme.txt

0 commit comments

Comments
 (0)