Permalink
Browse files

Making sure to get the properties of parent interfaces as well

  • Loading branch information...
1 parent 56c2b2f commit 29ef9b7c95f322ce0301052bb519c39c9c15d3ef @ayende ayende committed Dec 8, 2011
@@ -227,7 +227,7 @@ public PropertyInfo GetIdentityProperty(Type type)
if (currentIdPropertyCache.TryGetValue(type, out info))
return info;
- var identityProperty = type.GetProperties().FirstOrDefault(FindIdentityProperty);
+ var identityProperty = GetPropertiesForType(type).FirstOrDefault(FindIdentityProperty);
if (identityProperty!= null && identityProperty.DeclaringType != type)
{
@@ -243,6 +243,22 @@ public PropertyInfo GetIdentityProperty(Type type)
return identityProperty;
}
+ private static IEnumerable<PropertyInfo> GetPropertiesForType(Type type)
+ {
+ foreach (var propertyInfo in type.GetProperties())
+ {
+ yield return propertyInfo;
+ }
+
+ foreach (var @interface in type.GetInterfaces())
+ {
+ foreach (var propertyInfo in GetPropertiesForType(@interface))
+ {
+ yield return propertyInfo;
+ }
+ }
+ }
+
/// <summary>
/// Gets or sets the function to find the clr type of a document.
/// </summary>
@@ -0,0 +1,59 @@
+using System.Linq;
+using Raven.Client;
+using Raven.Client.Document;
+using Xunit;
+
+namespace Raven.Tests.MailingList
+{
+ public class JohanNilsson : RavenTest
+ {
+ internal interface IEntity
+ {
+ string Id2 { get; set; }
+ }
+
+ internal interface IDomainObject : IEntity
+ {
+ string ImportantProperty { get; }
+ }
+
+ class DomainObject : IDomainObject
+ {
+ public string Id2 { get; set; }
+ public string ImportantProperty { get; set; }
+ }
+
+ [Fact]
+ public void WithCustomizedTagNameAndIdentityProperty()
+ {
+ var id = string.Empty;
+ using (var store = NewDocumentStore())
+ {
+ var defaultFindIdentityProperty = store.Conventions.FindIdentityProperty;
+ store.Conventions.FindIdentityProperty = property =>
+ typeof(IEntity).IsAssignableFrom(property.DeclaringType)
+ ? property.Name == "Id2"
+ : defaultFindIdentityProperty(property);
+
+ store.Conventions.FindTypeTagName = type =>
+ typeof (IDomainObject).IsAssignableFrom(type)
+ ? "domainobjects"
+ : DocumentConvention.DefaultTypeTagName(type);
+
+ using (var session = store.OpenSession())
+ {
+ var domainObject = new DomainObject();
+ session.Store(domainObject);
+ var domainObject2 = new DomainObject();
+ session.Store(domainObject2);
+ session.SaveChanges();
+ id = domainObject.Id2;
+ }
+ var matchingDomainObjects = store.OpenSession().Query<IDomainObject>().Where(_ => _.Id2 == id).ToList();
+ Assert.Equal(matchingDomainObjects.Count, 1);
+ }
+
+
+ }
+ }
+}
@@ -561,6 +561,7 @@
<Compile Include="Linq\User.cs" />
<Compile Include="Linq\WhereClause.cs" />
<Compile Include="LocalClientTest.cs" />
+ <Compile Include="MailingList\JohanNilsson.cs" />
<Compile Include="MailingList\MapReduceIssue\CanPageThroughReduceResults.cs" />
<Compile Include="MailingList\DynamicQueryIndexSelection.cs" />
<Compile Include="MailingList\EnumAsInts.cs" />

0 comments on commit 29ef9b7

Please sign in to comment.