Часть журнала:
1922 [TSLVReader #1] DEBUG com.crystaldecisions.reports.formulas.Compiler - Compiling formula {@ean13}...
1922 [TSLVReader #1] INFO com.crystaldecisions.reports.formulas.Compiler - Formula {@ean13} did not compile: com.crystaldecisions.reports.formulas.FormulaException: Exception in the formulas '{@ean13}' a 'BarcodeEAN13('412345678901','567')':
the call to a function does not correspond to any overload of barcodeean13.
1922 [TSLVReader #1] WARN com.crystaldecisions.reports.reportdefinition.ReportDefinition - com.crystaldecisions.reports.formulas.FormulaException: Exception in the formulas '{@ean13}' a 'BarcodeEAN13('412345678901','567')':
the call to a function does not correspond to any overload of barcodeean13.
1923 [TSLVReader #1] ERROR com.crystaldecisions.reports.dataengine - Formula error: recompile formulas failed
com.crystaldecisions.reports.formulas.FormulaException: Exception in the formulas '{@ean13}' a 'BarcodeEAN13('412345678901','567')':
the call to a function does not correspond to any overload of barcodeean13.
at com.crystaldecisions.reports.formulas.j.a(SourceFile:3528)
at com.crystaldecisions.reports.formulas.j.a(SourceFile:3507)
at com.crystaldecisions.reports.formulas.c.a(SourceFile:1809)
at com.crystaldecisions.reports.formulas.j.a(SourceFile:3148)
at com.crystaldecisions.reports.formulas.j.a(SourceFile:295)
at com.crystaldecisions.reports.formulas.c.for(SourceFile:1225)
at com.crystaldecisions.reports.formulas.j.a(SourceFile:250)
at com.crystaldecisions.reports.formulas.j.do(SourceFile:74)
at com.crystaldecisions.reports.formulas.c.void(SourceFile:70)
at com.crystaldecisions.reports.formulas.r.a(SourceFile:90)
at com.crystaldecisions.reports.formulas.FormulaInfo.a(SourceFile:570)
at com.crystaldecisions.reports.formulas.FormulaService.compile(SourceFile:347)
(удаленный подход, связанный с атрибутами)
править: и вот является метамодель путем (таким образом, это работает с отображающимися файлами, а также приписанными объектами):
static TEntity Get<TEntity>(this DataContext ctx, int key) where TEntity : class
{
return Get<TEntity, int>(ctx, key);
}
static TEntity Get<TEntity, TKey>(this DataContext ctx, TKey key) where TEntity : class
{
var table = ctx.GetTable<TEntity>();
var pkProp = (from member in ctx.Mapping.GetMetaType(typeof(TEntity)).DataMembers
where member.IsPrimaryKey
select member.Member).Single();
ParameterExpression param = Expression.Parameter(typeof(TEntity), "x");
MemberExpression memberExp;
switch (pkProp.MemberType)
{
case MemberTypes.Field: memberExp = Expression.Field(param, (FieldInfo)pkProp); break;
case MemberTypes.Property: memberExp = Expression.Property(param, (PropertyInfo)pkProp); break;
default: throw new NotSupportedException("Invalid primary key member: " + pkProp.Name);
}
Expression body = Expression.Equal(
memberExp, Expression.Constant(key, typeof(TKey)));
var predicate = Expression.Lambda<Func<TEntity, bool>>(body, param);
return table.Single(predicate);
}
Возможно, можно найти что-то под Универсальными Предикатами по http://www.albahari.com/nutshell/predicatebuilder.aspx. Это - последний раздел на странице.
Необходимо было бы создать соответствующий интерфейс, который объекты получают из (если Вы не хотите сделать это с деревом выражений как пример Marc):
public interface IIdentifiedEntity
{
int Id { get; } // Set as well? Depends on your situation.
}
Затем можно записать:
public T GetItemById<T>(int id) where T : class, IIdentifiedEntity
{
Table<T> table = _db.GetTable<T>();
return table.Where(t => t.Id == id)
.Single();
}
var X = _db.table.Select(i => i.Id == id);
это возвратит IQueryable <T>