Auto Interface Implementation and Special Parameters
avber opened this issue · comments
Insight.Database 6.2.1
I'm having trouble with action and returns parameters.
IEnumerable GetLivingComplexes(int userId, int? regionId, int? cityArea, string ts);
this method works fine.
When I add an action
IEnumerable GetMioLivingComplexes(int? UserID, int? RegionID, int? CityAreaID, int? LivingComplexID, Action action);
Action act = (LivingComplexMioVM vm) => {
string ss = "";
};
it's not called.
When I add
IEnumerable GetMioLivingComplexes(int? UserID, int? RegionID, int? CityAreaID, int? LivingComplexID, ListReader reader);
var pr = new PostProcessRecordReader(
(reader, a) =>
{
return a;
});
var list = repo.GetMioLivingComplexes(null, regionID, null, null, Query.Returns(pr));
I get an error
Special Parameter returns must have type Insight.Database.Structure.IQueryReader1[[System.Collections.Generic.IEnumerable
1[[LivingComplexMioVM……………...
What am I doing wrong?
Thanks
Two things I can see that might help is https://github.com/jonwagner/Insight.Database/wiki/Specifying-Result-Structures#list-of-objects Using IList
instead of IEnumerable
.
Not sure the purpose of the Action but I would try changing that to a normal parameter.
Can you give us more details on your use case, including the structures of the data and the objects? It's not very common to combine interfaces and post-processing, so there is likely an easier way.
Well, initially I tried to convert SQL Server timestamps to long. In the end it was done on the database side.
I know I can use connection.Query to do it but if you don't want to repeat yourself, a repository class should be created.
Other use cases include calculating totals, generating thumbnails, decrypting values (saw it here on github).
It can be done using LINQ on the list of objects but that's an extra iteration of the collection.
Data and object structure is irrelevant because I'm not trying to implement 1-1 or 1-many relationships or use more than one result set.
I just got curious about how to do it with interfaces.
Got it. Let me see if I can make up a nice test case (or fix anything that's broken).
BTW - When people have to do post-processing with a repository class, they typically switch from an interface to an abstract class implementation. It's a nice happy medium:
public abstract class IMyRepository {
public abstract IList<Foo> AutoImplemented(int parameters);
public virtual IList<Goo> ManualImplemeneted(int parameters) {
return Query.Returns<Goo>(...);
}
}
or for the purist, I suppose you can make an interface and do a partial implementation:
public interface IMyRepository {
IList<Foo> AutoImplemented(int parameters);
IList<Goo> ManualImplemeneted(int parameters);
}
public class MyRepositoryImpl : IMyRepository {
public virtual IList<Goo> ManualImplemeneted(int parameters) {
return Query.Returns<Goo>(...);
}
// insight attempts to implement the rest of the methods.
}
I see.
I got it working using
var pr = new PostProcessRecordReader(
(reader, a) =>
{
return a;
});
ListReaderAdapter<IEnumerable, LivingComplexMioVM> listReaderAdapter = new ListReaderAdapter<IEnumerable, LivingComplexMioVM>(pr);