Upgrading NH3

--HG--
branch : NH3
This commit is contained in:
Sebastien Ros
2012-07-10 16:01:46 -07:00
parent 09e3d6d4c2
commit 9bed7cbaba
68 changed files with 12297 additions and 54188 deletions
@@ -62,17 +62,21 @@
<Reference Include="ClaySharp">
<HintPath>..\..\lib\claysharp\ClaySharp.dll</HintPath>
</Reference>
<Reference Include="FluentNHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nhibernate\FluentNHibernate.dll</HintPath>
</Reference>
<Reference Include="Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nhibernate\Iesi.Collections.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\moq\Moq.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\NHibernate.dll</HintPath>
</Reference>
<Reference Include="NHibernate.ByteCode.Castle, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\NHibernate.ByteCode.Castle.dll</HintPath>
<HintPath>..\..\lib\nhibernate\NHibernate.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.5.2.9222, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -79,7 +79,7 @@ namespace Orchard.Core.Tests.Scheduling {
_repository.Flush();
_executor.Sweep();
_repository.Flush();
Assert.That(_repository.Count(x => true), Is.EqualTo(1));
Assert.That(_repository.Count(x => x != null), Is.EqualTo(1));
}
@@ -85,7 +85,7 @@ namespace Orchard.Core.Tests.Scheduling {
_session.Flush();
_session.Clear();
var tasks = _repository.Fetch(x => true);
var tasks = _repository.Fetch(x => x != null);
Assert.That(tasks.Count(), Is.EqualTo(2));
Assert.That(tasks, Has.All.Property("TaskType").EqualTo("Ignore"));
@@ -1,5 +1,6 @@
using FluentNHibernate.Cfg.Db;
using Orchard.Data.Providers;
using MsSqlCeConfiguration = FluentNHibernate.Cfg.Db.MsSqlCeConfiguration;
namespace Orchard.Specs.Hosting {
public class TraceEnabledDataServicesProviderFactory : IDataServicesProviderFactory {
+6 -2
View File
@@ -69,7 +69,7 @@
</Reference>
<Reference Include="FluentNHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\FluentNHibernate.dll</HintPath>
<HintPath>..\..\lib\nhibernate\FluentNHibernate.dll</HintPath>
</Reference>
<Reference Include="FluentPath, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -79,13 +79,17 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\htmlagilitypack\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nhibernate\Iesi.Collections.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\log4net.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\NHibernate.dll</HintPath>
<HintPath>..\..\lib\nhibernate\NHibernate.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.5.2.9222, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -65,9 +65,9 @@
<Reference Include="ClaySharp">
<HintPath>..\..\lib\claysharp\ClaySharp.dll</HintPath>
</Reference>
<Reference Include="FluentNHibernate, Version=1.0.0.593, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
<Reference Include="FluentNHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\FluentNHibernate.dll</HintPath>
<HintPath>..\..\lib\nhibernate\FluentNHibernate.dll</HintPath>
</Reference>
<Reference Include="FluentPath">
<HintPath>..\..\lib\fluentpath\FluentPath.dll</HintPath>
@@ -76,6 +76,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\sharpziplib\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nhibernate\Iesi.Collections.dll</HintPath>
</Reference>
<Reference Include="IronRuby, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\dlr\IronRuby.dll</HintPath>
@@ -96,13 +100,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\moq\Moq.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<Reference Include="NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\NHibernate.dll</HintPath>
</Reference>
<Reference Include="NHibernate.ByteCode.Castle, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\NHibernate.ByteCode.Castle.dll</HintPath>
<HintPath>..\..\lib\nhibernate\NHibernate.dll</HintPath>
</Reference>
<Reference Include="NuGet.Core, Version=1.0.11220.104, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -299,7 +299,9 @@
<EmbeddedResource Include="Recipes\Services\FoldersData\Sample1\Module.txt" />
<EmbeddedResource Include="Recipes\Services\FoldersData\Sample1\Recipes\cms.recipe.xml" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\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.
@@ -201,7 +201,7 @@ namespace Orchard.Tests.ContentManagement {
_session.Clear();
var ascending = _manager.Query("gamma")
.OrderBy<GammaRecord, string>(x => x.Frap)
.OrderBy<GammaRecord>(x => x.Frap)
.List<GammaPart>().ToList();
Assert.That(ascending.Count(), Is.EqualTo(5));
@@ -229,11 +229,11 @@ namespace Orchard.Tests.ContentManagement {
_session.Flush();
var reverseById = _manager.Query()
.OrderByDescending<GammaRecord, int>(x => x.Id)
.OrderByDescending<GammaRecord>(x => x.Id)
.List();
var subset = _manager.Query()
.OrderByDescending<GammaRecord, int>(x => x.Id)
.OrderByDescending<GammaRecord>(x => x.Id)
.Slice(2, 3);
Assert.That(subset.Count(), Is.EqualTo(3));
@@ -367,7 +367,7 @@ namespace Orchard.Tests.ContentManagement {
_session.Flush();
_session.Clear();
foreach (var x in _container.Resolve<IRepository<ContentItemVersionRecord>>().Fetch(x => true)) {
foreach (var x in _container.Resolve<IRepository<ContentItemVersionRecord>>().Fetch(x => x != null)) {
Trace.WriteLine(string.Format("{0}/{1} #{2} published:{3} latest:{4}",
x.ContentItemRecord.Id,
x.Id,
@@ -45,7 +45,7 @@ namespace Orchard.Tests.DataMigration {
}
public void InitDb() {
foreach ( var record in _repository.Fetch(m => true) ) {
foreach ( var record in _repository.Fetch(m => m != null) ) {
_repository.Delete(record);
}
_repository.Flush();
+11
View File
@@ -1,15 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentNHibernate;
using FluentNHibernate.Automapping;
using FluentNHibernate.Automapping.Alterations;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Diagnostics;
using NHibernate;
using NHibernate.Tool.hbm2ddl;
using Orchard.Data;
using Orchard.Data.Providers;
using Orchard.Environment.ShellBuilders.Models;
using MsSqlCeConfiguration = FluentNHibernate.Cfg.Db.MsSqlCeConfiguration;
namespace Orchard.Tests {
public static class DataUtility {
@@ -65,6 +68,14 @@ namespace Orchard.Tests {
return _types;
}
public void LogSource(IDiagnosticLogger logger) {
throw new NotImplementedException();
}
public string GetIdentifier() {
throw new NotImplementedException();
}
#endregion
}
+11
View File
@@ -1,14 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentNHibernate;
using FluentNHibernate.Automapping;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Diagnostics;
using NHibernate.Criterion;
using NHibernate.Tool.hbm2ddl;
using NUnit.Framework;
using Orchard.Data.Providers;
using Orchard.Tests.Records;
using MsSqlCeConfiguration = FluentNHibernate.Cfg.Db.MsSqlCeConfiguration;
namespace Orchard.Tests {
[TestFixture]
@@ -26,6 +29,14 @@ namespace Orchard.Tests {
return _types;
}
public void LogSource(IDiagnosticLogger logger) {
throw new NotImplementedException();
}
public string GetIdentifier() {
throw new NotImplementedException();
}
#endregion
}
+1 -1
View File
@@ -31,7 +31,7 @@ namespace Orchard.Tests {
[Test]
public void WhereClauseShouldLimitResults() {
var foos = from f in _session.Linq<FooRecord>() where f.Name == "two" || f.Name == "one" select f;
var foos = from f in _session.Query<FooRecord>() where f.Name == "two" || f.Name == "one" select f;
Assert.That(foos.Count(), Is.EqualTo(2));
Assert.That(foos, Has.Some.Property("Name").EqualTo("one"));
@@ -75,9 +75,13 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\claysharp\ClaySharp.dll</HintPath>
</Reference>
<Reference Include="FluentNHibernate, Version=1.0.0.593, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
<Reference Include="FluentNHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\FluentNHibernate.dll</HintPath>
<HintPath>..\..\lib\nhibernate\FluentNHibernate.dll</HintPath>
</Reference>
<Reference Include="Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nhibernate\Iesi.Collections.dll</HintPath>
</Reference>
<Reference Include="IronRuby, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -102,17 +106,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\moq\Moq.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<Reference Include="NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\NHibernate.dll</HintPath>
</Reference>
<Reference Include="NHibernate.ByteCode.Castle, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\NHibernate.ByteCode.Castle.dll</HintPath>
</Reference>
<Reference Include="NHibernate.Linq, Version=1.0.0.4000, Culture=neutral, PublicKeyToken=444cf6a87fdab271, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\linqnhibernate\NHibernate.Linq.dll</HintPath>
<HintPath>..\..\lib\nhibernate\NHibernate.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.5.2.9222, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -12,38 +12,38 @@ namespace Orchard.Core.Containers.Extensions {
switch (partAndProperty) {
case "ContainablePart.Weight":
query = descendingOrder
? query.OrderByDescending<ContainablePartRecord, int>(record => record.Weight)
: query.OrderBy<ContainablePartRecord, int>(record => record.Weight);
? query.OrderByDescending<ContainablePartRecord>(record => record.Weight)
: query.OrderBy<ContainablePartRecord>(record => record.Weight);
break;
case "TitlePart.Title":
query = descendingOrder
? query.OrderByDescending<TitlePartRecord, string>(record => record.Title)
: query.OrderBy<TitlePartRecord, string>(record => record.Title);
? query.OrderByDescending<TitlePartRecord>(record => record.Title)
: query.OrderBy<TitlePartRecord>(record => record.Title);
break;
case "CustomPropertiesPart.CustomOne":
query = descendingOrder
? query.OrderByDescending<CustomPropertiesPartRecord, string>(record => record.CustomOne)
: query.OrderBy<CustomPropertiesPartRecord, string>(record => record.CustomOne);
? query.OrderByDescending<CustomPropertiesPartRecord>(record => record.CustomOne)
: query.OrderBy<CustomPropertiesPartRecord>(record => record.CustomOne);
break;
case "CustomPropertiesPart.CustomTwo":
query = descendingOrder
? query.OrderByDescending<CustomPropertiesPartRecord, string>(record => record.CustomTwo)
: query.OrderBy<CustomPropertiesPartRecord, string>(record => record.CustomTwo);
? query.OrderByDescending<CustomPropertiesPartRecord>(record => record.CustomTwo)
: query.OrderBy<CustomPropertiesPartRecord>(record => record.CustomTwo);
break;
case "CustomPropertiesPart.CustomThree":
query = descendingOrder
? query.OrderByDescending<CustomPropertiesPartRecord, string>(record => record.CustomThree)
: query.OrderBy<CustomPropertiesPartRecord, string>(record => record.CustomThree);
? query.OrderByDescending<CustomPropertiesPartRecord>(record => record.CustomThree)
: query.OrderBy<CustomPropertiesPartRecord>(record => record.CustomThree);
break;
case "CommonPart.CreatedUtc":
query = descendingOrder
? query.OrderByDescending<CommonPartRecord, DateTime?>(record => record.CreatedUtc)
: query.OrderBy<CommonPartRecord, DateTime?>(record => record.CreatedUtc);
? query.OrderByDescending<CommonPartRecord>(record => record.CreatedUtc)
: query.OrderBy<CommonPartRecord>(record => record.CreatedUtc);
break;
default: // "CommonPart.PublishedUtc"
query = descendingOrder
? query.OrderByDescending<CommonPartRecord, DateTime?>(record => record.PublishedUtc)
: query.OrderBy<CommonPartRecord, DateTime?>(record => record.PublishedUtc);
? query.OrderByDescending<CommonPartRecord>(record => record.PublishedUtc)
: query.OrderBy<CommonPartRecord>(record => record.PublishedUtc);
break;
}
@@ -71,14 +71,14 @@ namespace Orchard.Core.Contents.Controllers {
switch (model.Options.OrderBy) {
case ContentsOrder.Modified:
//query = query.OrderByDescending<ContentPartRecord, int>(ci => ci.ContentItemRecord.Versions.Single(civr => civr.Latest).Id);
query = query.OrderByDescending<CommonPartRecord, DateTime?>(cr => cr.ModifiedUtc);
query = query.OrderByDescending<CommonPartRecord>(cr => cr.ModifiedUtc);
break;
case ContentsOrder.Published:
query = query.OrderByDescending<CommonPartRecord, DateTime?>(cr => cr.PublishedUtc);
query = query.OrderByDescending<CommonPartRecord>(cr => cr.PublishedUtc);
break;
case ContentsOrder.Created:
//query = query.OrderByDescending<ContentPartRecord, int>(ci => ci.Id);
query = query.OrderByDescending<CommonPartRecord, DateTime?>(cr => cr.CreatedUtc);
query = query.OrderByDescending<CommonPartRecord>(cr => cr.CreatedUtc);
break;
}
@@ -54,7 +54,7 @@ namespace Orchard.Core.Settings.Descriptor {
}
private ShellDescriptorRecord GetDescriptorRecord() {
return _shellDescriptorRepository.Get(x => true);
return _shellDescriptorRepository.Get(x => x != null);
}
public void UpdateShellDescriptor(int priorSerialNumber, IEnumerable<ShellFeature> enabledFeatures, IEnumerable<ShellParameter> parameters) {
@@ -19,7 +19,7 @@ namespace Orchard.Core.Settings.State {
}
public ShellState GetShellState() {
var stateRecord = _shellStateRepository.Get(x => true) ?? new ShellStateRecord();
var stateRecord = _shellStateRepository.Get(x => x != null) ?? new ShellStateRecord();
var descriptor = _shellDescriptorManager.GetShellDescriptor();
var extraFeatures = descriptor == null ? Enumerable.Empty<string>() : descriptor.Features
.Select(r => r.Name)
@@ -40,7 +40,7 @@ namespace Orchard.Core.Settings.State {
}
private ShellFeatureStateRecord FeatureRecord(string name) {
var stateRecord = _shellStateRepository.Get(x => true) ?? new ShellStateRecord();
var stateRecord = _shellStateRepository.Get(x => x != null) ?? new ShellStateRecord();
var record = stateRecord.Features.SingleOrDefault(x => x.Name == name);
if (record == null) {
record = new ShellFeatureStateRecord { Name = name };
@@ -69,7 +69,7 @@ namespace Orchard.Comments.Controllers {
var pagerShape = Shape.Pager(pager).TotalItemCount(comments.Count());
var entries = comments
.OrderByDescending<CommentPartRecord, DateTime?>(cpr => cpr.CommentDateUtc)
.OrderByDescending<CommentPartRecord>(cpr => cpr.CommentDateUtc)
.Slice(pager.GetStartIndex(), pager.PageSize)
.ToList()
.Select(comment => CreateCommentEntry(comment.Record));
@@ -132,13 +132,13 @@ namespace Orchard.Lists.Controllers {
: query.Join<CommonPartRecord>().Where(cr => cr.Container.Id == containerId);
switch (orderBy) {
case ContentsOrder.Modified:
query = query.OrderByDescending<CommonPartRecord, DateTime?>(cr => cr.ModifiedUtc);
query = query.OrderByDescending<CommonPartRecord>(cr => cr.ModifiedUtc);
break;
case ContentsOrder.Published:
query = query.OrderByDescending<CommonPartRecord, DateTime?>(cr => cr.PublishedUtc);
query = query.OrderByDescending<CommonPartRecord>(cr => cr.PublishedUtc);
break;
case ContentsOrder.Created:
query = query.OrderByDescending<CommonPartRecord, DateTime?>(cr => cr.CreatedUtc);
query = query.OrderByDescending<CommonPartRecord>(cr => cr.CreatedUtc);
break;
}
@@ -40,8 +40,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="NHibernate">
<HintPath>..\..\..\..\lib\fluentnhibernate\NHibernate.dll</HintPath>
<Reference Include="NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\nhibernate\NHibernate.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
-3
View File
@@ -55,9 +55,6 @@
<HintPath>..\..\lib\aspnetmvc\Microsoft.Web.Infrastructure.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NHibernate.ByteCode.Castle, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<HintPath>..\..\lib\fluentnhibernate\NHibernate.ByteCode.Castle.dll</HintPath>
</Reference>
<Reference Include="NuGet.Core, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\lib\nuget\NuGet.Core.dll</HintPath>
<Private>True</Private>
@@ -1,29 +1,33 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection.Emit;
using FluentNHibernate;
using NHibernate;
using NHibernate.Criterion;
using NHibernate.Impl;
using NHibernate.Linq;
using Orchard.ContentManagement.Records;
using Orchard.Data;
using Orchard.Utility.Extensions;
using NHibernate.Transform;
using NHibernate.SqlCommand;
using System.Reflection;
using Orchard.Data.Conventions;
using Expression = System.Linq.Expressions.Expression;
namespace Orchard.ContentManagement {
public class DefaultContentQuery : IContentQuery {
private readonly ISessionLocator _sessionLocator;
private ISession _session;
private ICriteria _itemVersionCriteria;
private IQueryOver<ContentItemVersionRecord, ContentItemVersionRecord> _itemVersionQueryOver;
private readonly IDictionary<string, object> _joins;
private VersionOptions _versionOptions;
public DefaultContentQuery(IContentManager contentManager, ISessionLocator sessionLocator) {
_sessionLocator = sessionLocator;
ContentManager = contentManager;
_joins = new Dictionary<string, object>();
}
public IContentManager ContentManager { get; private set; }
@@ -34,40 +38,60 @@ namespace Orchard.ContentManagement {
return _session;
}
ICriteria BindCriteriaByPath(ICriteria criteria, string path) {
return criteria.GetCriteriaByPath(path) ?? criteria.CreateCriteria(path);
IQueryOver<ContentItemVersionRecord, TRecord> BindQueryOverByPath<TRecord, U>(IQueryOver<ContentItemVersionRecord, U> queryOver, string name) {
if (_joins.ContainsKey(typeof(TRecord).Name)) {
return (IQueryOver<ContentItemVersionRecord, TRecord>)_joins[typeof(TRecord).Name];
}
// public TPartRecord TPartRecord {get;set;}
var dynamicMethod = new DynamicMethod(name, typeof(TRecord), null, typeof(U));
var syntheticMethod = new ContentItemAlteration.SyntheticMethodInfo(dynamicMethod, typeof(U));
var syntheticProperty = new ContentItemAlteration.SyntheticPropertyInfo(syntheticMethod);
// record => record.TPartRecord
var parameter = Expression.Parameter(typeof(U), "record");
var syntheticExpression = (Expression<Func<U, TRecord>>)Expression.Lambda(
typeof(Func<U, TRecord>),
Expression.Property(parameter, syntheticProperty),
parameter);
var join = queryOver.JoinQueryOver(syntheticExpression);
_joins[typeof(TRecord).Name] = join;
return join;
}
ICriteria BindTypeCriteria() {
IQueryOver<ContentItemVersionRecord, ContentTypeRecord> BindTypeQueryOver() {
// ([ContentItemVersionRecord] >join> [ContentItemRecord]) >join> [ContentType]
return BindCriteriaByPath(BindItemCriteria(), "ContentType");
return BindQueryOverByPath<ContentTypeRecord, ContentItemRecord>(BindItemQueryOver(), "ContentType");
}
ICriteria BindItemCriteria() {
IQueryOver<ContentItemVersionRecord, ContentItemRecord> BindItemQueryOver() {
// [ContentItemVersionRecord] >join> [ContentItemRecord]
return BindCriteriaByPath(BindItemVersionCriteria(), "ContentItemRecord");
return BindQueryOverByPath<ContentItemRecord, ContentItemVersionRecord>(BindItemVersionQueryOver(), "ContentItemRecord");
}
ICriteria BindItemVersionCriteria() {
if (_itemVersionCriteria == null) {
_itemVersionCriteria = BindSession().CreateCriteria<ContentItemVersionRecord>();
IQueryOver<ContentItemVersionRecord, ContentItemVersionRecord> BindItemVersionQueryOver() {
if (_itemVersionQueryOver == null) {
_itemVersionQueryOver = BindSession().QueryOver<ContentItemVersionRecord>();
}
return _itemVersionCriteria;
return _itemVersionQueryOver;
}
ICriteria BindPartCriteria<TRecord>() where TRecord : ContentPartRecord {
if (typeof(TRecord).IsSubclassOf(typeof(ContentPartVersionRecord))) {
return BindCriteriaByPath(BindItemVersionCriteria(), typeof(TRecord).Name);
IQueryOver<ContentItemVersionRecord, TRecord> BindPartQueryOver<TRecord>() where TRecord : ContentPartRecord {
if (typeof (TRecord).IsSubclassOf(typeof (ContentPartVersionRecord))) {
return BindQueryOverByPath<TRecord, ContentItemVersionRecord>(BindItemVersionQueryOver(), typeof(TRecord).Name);
}
return BindCriteriaByPath(BindItemCriteria(), typeof(TRecord).Name);
return BindQueryOverByPath<TRecord, ContentItemRecord>(BindItemQueryOver(), typeof(TRecord).Name);
}
private void ForType(params string[] contentTypeNames) {
if (contentTypeNames != null && contentTypeNames.Length != 0)
BindTypeCriteria().Add(Restrictions.InG("Name", contentTypeNames));
BindTypeQueryOver().Where(Restrictions.InG("Name", contentTypeNames));
}
public void ForVersion(VersionOptions options) {
@@ -76,86 +100,48 @@ namespace Orchard.ContentManagement {
private void Where<TRecord>() where TRecord : ContentPartRecord {
// this simply demands an inner join
BindPartCriteria<TRecord>();
BindPartQueryOver<TRecord>();
}
private void Where<TRecord>(Expression<Func<TRecord, bool>> predicate) where TRecord : ContentPartRecord {
// build a linq to nhibernate expression
var options = new QueryOptions();
var queryProvider = new NHibernateQueryProvider(BindSession(), options);
var queryable = new Query<TRecord>(queryProvider, options).Where(predicate);
// translate it into the nhibernate ICriteria implementation
var criteria = (CriteriaImpl)queryProvider.TranslateExpression(queryable.Expression);
// attach the criterion from the predicate to this query's criteria for the record
var recordCriteria = BindPartCriteria<TRecord>();
foreach (var expressionEntry in criteria.IterateExpressionEntries()) {
recordCriteria.Add(expressionEntry.Criterion);
}
BindPartQueryOver<TRecord>().Where(predicate);
}
private void OrderBy<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) where TRecord : ContentPartRecord {
// build a linq to nhibernate expression
var options = new QueryOptions();
var queryProvider = new NHibernateQueryProvider(BindSession(), options);
var queryable = new Query<TRecord>(queryProvider, options).OrderBy(keySelector);
// translate it into the nhibernate ordering
var criteria = (CriteriaImpl)queryProvider.TranslateExpression(queryable.Expression);
// attaching orderings to the query's criteria
var recordCriteria = BindPartCriteria<TRecord>();
foreach (var ordering in criteria.IterateOrderings()) {
recordCriteria.AddOrder(ordering.Order);
}
private void OrderBy<TRecord>(Expression<Func<TRecord, object>> keySelector) where TRecord : ContentPartRecord {
BindPartQueryOver<TRecord>().OrderBy(keySelector).Asc();
}
private void OrderByDescending<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) where TRecord : ContentPartRecord {
// build a linq to nhibernate expression
var options = new QueryOptions();
var queryProvider = new NHibernateQueryProvider(BindSession(), options);
var queryable = new Query<TRecord>(queryProvider, options).OrderByDescending(keySelector);
// translate it into the nhibernate ICriteria implementation
var criteria = (CriteriaImpl)queryProvider.TranslateExpression(queryable.Expression);
// attaching orderings to the query's criteria
var recordCriteria = BindPartCriteria<TRecord>();
foreach (var ordering in criteria.IterateOrderings()) {
recordCriteria.AddOrder(ordering.Order);
}
private void OrderByDescending<TRecord>(Expression<Func<TRecord, object>> keySelector) where TRecord : ContentPartRecord {
BindPartQueryOver<TRecord>().OrderBy(keySelector).Desc();
}
private IEnumerable<ContentItem> Slice(int skip, int count) {
var criteria = BindItemVersionCriteria();
criteria.ApplyVersionOptionsRestrictions(_versionOptions);
var queryOver = BindItemVersionQueryOver();
criteria.SetFetchMode("ContentItemRecord", FetchMode.Eager);
criteria.SetFetchMode("ContentItemRecord.ContentType", FetchMode.Eager);
queryOver.ApplyVersionOptionsRestrictions(_versionOptions);
// TODO: put 'removed false' filter in place
if (skip != 0) {
criteria = criteria.SetFirstResult(skip);
queryOver.Skip(skip);
}
if (count != 0) {
criteria = criteria.SetMaxResults(count);
queryOver.Take(count);
}
return criteria
.List<ContentItemVersionRecord>()
.Select(x => ContentManager.Get(x.Id, VersionOptions.VersionRecord(x.Id)))
.ToReadOnlyCollection();
return new ReadOnlyCollection<ContentItem>(queryOver
.List<ContentItemVersionRecord>()
.Select(x => ContentManager.Get(x.Id, VersionOptions.VersionRecord(x.Id)))
.ToList());
}
int Count() {
var criteria = (ICriteria)BindItemVersionCriteria().Clone();
criteria.ClearOrders();
var queryOver = BindItemVersionQueryOver();
queryOver.ClearOrders();
criteria.ApplyVersionOptionsRestrictions(_versionOptions);
queryOver.ApplyVersionOptionsRestrictions(_versionOptions);
return criteria.SetProjection(Projections.RowCount()).UniqueResult<Int32>();
return queryOver.Select(Projections.RowCount()).FutureValue<int>().Value;
}
IContentQuery<TPart> IContentQuery.ForPart<TPart>() {
@@ -209,12 +195,12 @@ namespace Orchard.ContentManagement {
return new ContentQuery<T, TRecord>(_query);
}
IContentQuery<T, TRecord> IContentQuery<T>.OrderBy<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) {
IContentQuery<T, TRecord> IContentQuery<T>.OrderBy<TRecord>(Expression<Func<TRecord, object>> keySelector) {
_query.OrderBy(keySelector);
return new ContentQuery<T, TRecord>(_query);
return new ContentQuery<T, TRecord>(_query);
}
IContentQuery<T, TRecord> IContentQuery<T>.OrderByDescending<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) {
IContentQuery<T, TRecord> IContentQuery<T>.OrderByDescending<TRecord>(Expression<Func<TRecord, object>> keySelector) {
_query.OrderByDescending(keySelector);
return new ContentQuery<T, TRecord>(_query);
}
@@ -238,24 +224,23 @@ namespace Orchard.ContentManagement {
return this;
}
IContentQuery<T, TR> IContentQuery<T, TR>.OrderBy<TKey>(Expression<Func<TR, TKey>> keySelector) {
IContentQuery<T, TR> IContentQuery<T, TR>.OrderBy(Expression<Func<TR, object>> keySelector) {
_query.OrderBy(keySelector);
return this;
}
IContentQuery<T, TR> IContentQuery<T, TR>.OrderByDescending<TKey>(Expression<Func<TR, TKey>> keySelector) {
IContentQuery<T, TR> IContentQuery<T, TR>.OrderByDescending(Expression<Func<TR, object>> keySelector) {
_query.OrderByDescending(keySelector);
return this;
}
public IContentQuery<T, TR> WithQueryHints(QueryHints hints) {
if (hints == QueryHints.Empty) {
return this;
}
var contentItemVersionCriteria = _query.BindItemVersionCriteria();
var contentItemCriteria = _query.BindItemCriteria();
var contentItemVersionCriteria = _query.BindItemVersionQueryOver();
var contentItemCriteria = _query.BindItemQueryOver();
var contentItemMetadata = _query._session.SessionFactory.GetClassMetadata(typeof(ContentItemRecord));
var contentItemVersionMetadata = _query._session.SessionFactory.GetClassMetadata(typeof(ContentItemVersionRecord));
@@ -268,18 +253,20 @@ namespace Orchard.ContentManagement {
// locate hints that match properties in the ContentItemVersionRecord
foreach (var hit in contentItemVersionMetadata.PropertyNames.Where(hintDictionary.ContainsKey).SelectMany(key => hintDictionary[key])) {
contentItemVersionCriteria.SetFetchMode(hit.Hint, FetchMode.Eager);
hit.Segments.Take(hit.Segments.Count() - 1).Aggregate(contentItemVersionCriteria, ExtendCriteria);
// todo
// contentItemVersionCriteria.Fetch(hit.Hint);
// hit.Segments.Take(hit.Segments.Count() - 1).Aggregate(contentItemVersionCriteria, ExtendCriteria);
}
// locate hints that match properties in the ContentItemRecord
foreach (var hit in contentItemMetadata.PropertyNames.Where(hintDictionary.ContainsKey).SelectMany(key => hintDictionary[key])) {
contentItemVersionCriteria.SetFetchMode("ContentItemRecord." + hit.Hint, FetchMode.Eager);
hit.Segments.Take(hit.Segments.Count() - 1).Aggregate(contentItemCriteria, ExtendCriteria);
// todo
// contentItemVersionCriteria.Fetch("ContentItemRecord." + hit.Hint, FetchMode.Eager);
// hit.Segments.Take(hit.Segments.Count() - 1).Aggregate(contentItemCriteria, ExtendCriteria);
}
if (hintDictionary.SelectMany(x => x.Value).Any(x => x.Segments.Count() > 1))
contentItemVersionCriteria.SetResultTransformer(new DistinctRootEntityResultTransformer());
contentItemVersionCriteria.TransformUsing(new DistinctRootEntityResultTransformer());
return this;
}
@@ -305,18 +292,18 @@ namespace Orchard.ContentManagement {
}
internal static class CriteriaExtensions {
internal static void ApplyVersionOptionsRestrictions(this ICriteria criteria, VersionOptions versionOptions) {
internal static void ApplyVersionOptionsRestrictions<T>(this IQueryOver<T, T> criteria, VersionOptions versionOptions) {
if (versionOptions == null) {
criteria.Add(Restrictions.Eq("Published", true));
criteria.Where(Restrictions.Eq("Published", true));
}
else if (versionOptions.IsPublished) {
criteria.Add(Restrictions.Eq("Published", true));
criteria.Where(Restrictions.Eq("Published", true));
}
else if (versionOptions.IsLatest) {
criteria.Add(Restrictions.Eq("Latest", true));
criteria.Where(Restrictions.Eq("Latest", true));
}
else if (versionOptions.IsDraft) {
criteria.Add(Restrictions.And(
criteria.Where(Restrictions.And(
Restrictions.Eq("Latest", true),
Restrictions.Eq("Published", false)));
}
@@ -21,16 +21,16 @@ namespace Orchard.ContentManagement {
IContentQuery<TPart, TRecord> Join<TRecord>() where TRecord : ContentPartRecord;
IContentQuery<TPart, TRecord> Where<TRecord>(Expression<Func<TRecord, bool>> predicate) where TRecord : ContentPartRecord;
IContentQuery<TPart, TRecord> OrderBy<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) where TRecord : ContentPartRecord;
IContentQuery<TPart, TRecord> OrderByDescending<TRecord, TKey>(Expression<Func<TRecord, TKey>> keySelector) where TRecord : ContentPartRecord;
IContentQuery<TPart, TRecord> OrderBy<TRecord>(Expression<Func<TRecord, object>> keySelector) where TRecord : ContentPartRecord;
IContentQuery<TPart, TRecord> OrderByDescending<TRecord>(Expression<Func<TRecord, object>> keySelector) where TRecord : ContentPartRecord;
}
public interface IContentQuery<TPart, TRecord> : IContentQuery<TPart> where TPart : IContent where TRecord : ContentPartRecord {
new IContentQuery<TPart, TRecord> ForVersion(VersionOptions options);
IContentQuery<TPart, TRecord> Where(Expression<Func<TRecord, bool>> predicate);
IContentQuery<TPart, TRecord> OrderBy<TKey>(Expression<Func<TRecord, TKey>> keySelector);
IContentQuery<TPart, TRecord> OrderByDescending<TKey>(Expression<Func<TRecord, TKey>> keySelector);
IContentQuery<TPart, TRecord> OrderBy(Expression<Func<TRecord, object>> keySelector);
IContentQuery<TPart, TRecord> OrderByDescending(Expression<Func<TRecord, object>> keySelector);
IContentQuery<TPart, TRecord> WithQueryHints(QueryHints hints);
IContentQuery<TPart, TRecord> WithQueryHintsFor(string contentType);
@@ -1,16 +1,18 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using FluentNHibernate.Automapping;
using FluentNHibernate.Automapping.Alterations;
using JetBrains.Annotations;
using Orchard.Environment.ShellBuilders.Models;
namespace Orchard.ContentManagement.Records {
class ContentItemAlteration : IAutoMappingAlteration {
private readonly IEnumerable<RecordBlueprint> _recordDescriptors;
[UsedImplicitly]
public ContentItemAlteration() {
_recordDescriptors = Enumerable.Empty<RecordBlueprint>();
}
@@ -53,7 +55,20 @@ namespace Orchard.ContentManagement.Records {
class Alteration<TItemRecord, TPartRecord> : IAlteration<TItemRecord> {
public void Override(AutoMapping<TItemRecord> mapping) {
mapping.References<TPartRecord>(typeof(TItemRecord), typeof(TPartRecord).Name, typeof(TPartRecord).Name)
// public TPartRecord TPartRecord {get;set;}
var name = typeof(TPartRecord).Name;
var dynamicMethod = new DynamicMethod(name, typeof(TPartRecord), null, typeof(TItemRecord));
var syntheticMethod = new SyntheticMethodInfo(dynamicMethod, typeof(TItemRecord));
var syntheticProperty = new SyntheticPropertyInfo(syntheticMethod);
// record => record.TPartRecord
var parameter = Expression.Parameter(typeof(TItemRecord), "record");
var syntheticExpression = (Expression<Func<TItemRecord, TPartRecord>>)Expression.Lambda(
typeof(Func<TItemRecord, TPartRecord>),
Expression.Property(parameter, syntheticProperty),
parameter);
mapping.References(syntheticExpression)
.Access.NoOp()
.Column("Id")
.ForeignKey("none") // prevent foreign key constraint from ContentItem(Version)Record to TPartRecord
@@ -63,5 +78,163 @@ namespace Orchard.ContentManagement.Records {
.Cascade.All();
}
}
/// <summary>
/// Synthetic method around a dynamic method. We need this so that we can
/// override the "static" method attributes, and also return a valid "DeclaringType".
/// </summary>
public class SyntheticMethodInfo : MethodInfo {
private readonly DynamicMethod _dynamicMethod;
private readonly Type _declaringType;
public SyntheticMethodInfo(DynamicMethod dynamicMethod, Type declaringType) {
_dynamicMethod = dynamicMethod;
_declaringType = declaringType;
}
public override object[] GetCustomAttributes(bool inherit) {
return _dynamicMethod.GetCustomAttributes(inherit);
}
public override bool IsDefined(Type attributeType, bool inherit) {
return IsDefined(attributeType, inherit);
}
public override ParameterInfo[] GetParameters() {
return _dynamicMethod.GetParameters();
}
public override MethodImplAttributes GetMethodImplementationFlags() {
return _dynamicMethod.GetMethodImplementationFlags();
}
public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) {
return _dynamicMethod.Invoke(obj, invokeAttr, binder, parameters, culture);
}
public override MethodInfo GetBaseDefinition() {
return _dynamicMethod.GetBaseDefinition();
}
public override ICustomAttributeProvider ReturnTypeCustomAttributes {
get { return ReturnTypeCustomAttributes; }
}
public override string Name {
get { return _dynamicMethod.Name; }
}
public override Type DeclaringType {
get { return _declaringType; }
}
public override Type ReflectedType {
get { return _dynamicMethod.ReflectedType; }
}
public override RuntimeMethodHandle MethodHandle {
get { return _dynamicMethod.MethodHandle; }
}
public override MethodAttributes Attributes {
get { return _dynamicMethod.Attributes & ~MethodAttributes.Static; }
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
return _dynamicMethod.GetCustomAttributes(attributeType, inherit);
}
public override Type ReturnType {
get { return _dynamicMethod.ReturnType; }
}
}
/// <summary>
/// Synthetic property around a method info (the "getter" method).
/// This is a minimal implementation enabling support for AutoMapping.References.
/// </summary>
public class SyntheticPropertyInfo : PropertyInfo {
private readonly MethodInfo _getMethod;
public SyntheticPropertyInfo(MethodInfo getMethod) {
_getMethod = getMethod;
}
public override object[] GetCustomAttributes(bool inherit) {
throw new NotImplementedException();
}
public override bool IsDefined(Type attributeType, bool inherit) {
throw new NotImplementedException();
}
public override object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) {
throw new NotImplementedException();
}
public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) {
throw new NotImplementedException();
}
public override MethodInfo[] GetAccessors(bool nonPublic) {
throw new NotImplementedException();
}
public override MethodInfo GetGetMethod(bool nonPublic) {
return _getMethod;
}
public override MethodInfo GetSetMethod(bool nonPublic) {
return null;
}
public override ParameterInfo[] GetIndexParameters() {
throw new NotImplementedException();
}
public override string Name {
get { return _getMethod.Name; }
}
public override Type DeclaringType {
get { return _getMethod.DeclaringType; }
}
public override Type ReflectedType {
get { return _getMethod.ReflectedType; }
}
public override Type PropertyType {
get { return _getMethod.ReturnType; }
}
public override PropertyAttributes Attributes {
get { throw new NotImplementedException(); }
}
public override bool CanRead {
get { return true; }
}
public override bool CanWrite {
get { throw new NotImplementedException(); }
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
throw new NotImplementedException();
}
public override int MetadataToken {
get { return 0; }
}
public override Module Module {
get { return null; }
}
public override MemberTypes MemberType {
get { return MemberTypes.Property; }
}
}
}
}
}
@@ -17,6 +17,6 @@ namespace Orchard.ContentManagement.Records {
[StringLengthMax]
public virtual string Data { get { return Infoset.Data; } set { Infoset.Data = value; } }
public virtual Infoset Infoset { get; private set; }
public virtual Infoset Infoset { get; protected set; }
}
}
@@ -16,6 +16,6 @@ namespace Orchard.ContentManagement.Records {
[StringLengthMax]
public virtual string Data { get { return Infoset.Data; } set { Infoset.Data = value; } }
public virtual Infoset Infoset { get; private set; }
public virtual Infoset Infoset { get; protected set; }
}
}
@@ -23,7 +23,8 @@ namespace Orchard.Data.Conventions
public void Accept(IAcceptanceCriteria<IManyToOneInspector> criteria)
{
criteria.Expect(x => x.Property != null && x.Property.IsDefined(typeof(AggregateAttribute), false));
// todo
// criteria.Expect(x => x.Property != null && x.Property.IsDefined(typeof(AggregateAttribute), false));
}
public void Apply(IOneToManyCollectionInstance instance)
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentNHibernate;
using FluentNHibernate.Automapping;
using FluentNHibernate.Automapping.Alterations;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Conventions.Helpers;
using FluentNHibernate.Diagnostics;
using NHibernate.Cfg;
using Orchard.ContentManagement.Records;
using Orchard.Data.Conventions;
@@ -48,6 +50,14 @@ namespace Orchard.Data.Providers {
public TypeSource(IEnumerable<RecordBlueprint> recordDescriptors) { _recordDescriptors = recordDescriptors; }
public IEnumerable<Type> GetTypes() { return _recordDescriptors.Select(descriptor => descriptor.Type); }
public void LogSource(IDiagnosticLogger logger) {
throw new NotImplementedException();
}
public string GetIdentifier() {
throw new NotImplementedException();
}
}
}
}
@@ -4,6 +4,7 @@ using System.Data;
using System.IO;
using System.Reflection;
using FluentNHibernate.Cfg.Db;
using NHibernate.Dialect;
using NHibernate.Driver;
using NHibernate.SqlTypes;
@@ -29,7 +30,7 @@ namespace Orchard.Data.Providers {
}
public override IPersistenceConfigurer GetPersistenceConfigurer(bool createDatabase) {
var persistence = MsSqlCeConfiguration.Standard;
var persistence = MsSqlCeConfiguration.MsSqlCe40;
if (createDatabase) {
File.Delete(_fileName);
@@ -104,4 +105,45 @@ namespace Orchard.Data.Providers {
}
}
}
public class MsSqlCeConfiguration : PersistenceConfiguration<MsSqlCeConfiguration> {
protected MsSqlCeConfiguration() {
Driver<CustomSqlServerCeDriver>();
}
public static MsSqlCeConfiguration MsSqlCe40 {
get { return new MsSqlCeConfiguration().Dialect<CustomMsSqlCe40Dialect>(); }
}
/// <summary>
/// Custom driver so that Text/NText fields are not truncated at 4000 characters
/// </summary>
public class CustomSqlServerCeDriver : SqlServerCeDriver {
protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType) {
base.InitializeParameter(dbParam, name, sqlType);
PropertyInfo dbParamSqlDbTypeProperty = dbParam.GetType().GetProperty("SqlDbType");
if (sqlType.Length <= 4000) {
return;
}
switch (sqlType.DbType) {
case DbType.String:
dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.NText, null);
break;
case DbType.AnsiString:
dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.Text, null);
break;
}
}
}
public class CustomMsSqlCe40Dialect : MsSqlCe40Dialect {
public override bool SupportsVariableLimit {
get { return true; }
}
}
}
}
+3 -3
View File
@@ -8,7 +8,7 @@ using Orchard.Logging;
using Orchard.Utility.Extensions;
namespace Orchard.Data {
public class Repository<T> : IRepository<T> {
public class Repository<T> : IRepository<T> where T : class {
private readonly ISessionLocator _sessionLocator;
public Repository(ISessionLocator sessionLocator) {
@@ -27,7 +27,7 @@ namespace Orchard.Data {
}
public virtual IQueryable<T> Table {
get { return Session.Linq<T>(); }
get { return Session.Query<T>(); }
}
#region IRepository<T> Members
@@ -99,7 +99,7 @@ namespace Orchard.Data {
public virtual void Update(T entity) {
Logger.Debug("Update {0}", entity);
Session.Evict(entity);
Session.SaveOrUpdateCopy(entity);
Session.Merge(entity);
}
public virtual void Delete(T entity) {
+8 -13
View File
@@ -66,22 +66,23 @@
<Reference Include="Castle.Core, Version=1.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Castle Windsor 2.0\bin\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Castle.DynamicProxy2, Version=2.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Castle Windsor 2.0\bin\Castle.DynamicProxy2.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ClaySharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\claysharp\ClaySharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FluentNHibernate, Version=1.0.0.593, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
<Reference Include="FluentNHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\FluentNHibernate.dll</HintPath>
<Private>True</Private>
<HintPath>..\..\lib\nhibernate\FluentNHibernate.dll</HintPath>
</Reference>
<Reference Include="Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nhibernate\Iesi.Collections.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -89,15 +90,9 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<Reference Include="NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\NHibernate.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NHibernate.Linq, Version=1.0.0.4000, Culture=neutral, PublicKeyToken=444cf6a87fdab271, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\linqnhibernate\NHibernate.Linq.dll</HintPath>
<Private>True</Private>
<HintPath>..\..\lib\nhibernate\NHibernate.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations">