Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 2944581

Browse files
committed
Can create table with Indexer
1 parent 2b296e5 commit 2944581

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/ServiceStack.OrmLite/OrmLiteConfigExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ internal static ModelDefinition GetModelDefinition(this Type modelType)
9393
var i = 0;
9494
foreach (var propertyInfo in objProperties)
9595
{
96+
if (propertyInfo.GetIndexParameters().Length > 0)
97+
continue; //Is Indexer
98+
9699
var sequenceAttr = propertyInfo.FirstAttribute<SequenceAttribute>();
97100
var computeAttr = propertyInfo.FirstAttribute<ComputeAttribute>();
98101
var decimalAttribute = propertyInfo.FirstAttribute<DecimalLengthAttribute>();

tests/ServiceStack.OrmLite.Tests/OrmLiteCreateTableTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using NUnit.Framework;
34
using ServiceStack.Common.Tests.Models;
45
using ServiceStack.OrmLite.Tests.Shared;
@@ -263,5 +264,46 @@ public void Can_create_table_with_all_number_types()
263264
Assert.That(ModelWithNumerics.ModelWithNumericsComparer.Equals(fromDb, defaultValues));
264265
}
265266
}
267+
268+
public class ModelWithIndexer
269+
{
270+
public int Id { get; set; }
271+
public string Name { get; set; }
272+
273+
public ModelWithIndexer()
274+
{
275+
Attributes = new Dictionary<string, object>();
276+
}
277+
278+
public Object this[string attributeName]
279+
{
280+
get
281+
{
282+
return Attributes[attributeName];
283+
}
284+
set
285+
{
286+
Attributes[attributeName] = value;
287+
}
288+
}
289+
290+
Dictionary<string, object> Attributes { get; set; }
291+
}
292+
293+
[Test]
294+
public void Can_create_table_ModelWithIndexer()
295+
{
296+
using (var db = OpenDbConnection())
297+
{
298+
db.DropAndCreateTable<ModelWithIndexer>();
299+
300+
db.Insert(new ModelWithIndexer { Id = 1, Name = "foo" });
301+
302+
var row = db.SingleById<ModelWithIndexer>(1);
303+
304+
Assert.That(row.Name, Is.EqualTo("foo"));
305+
}
306+
}
307+
266308
}
267309
}

0 commit comments

Comments
 (0)