You essentially have two different functions in each method:
- Property Request
- Match this object to another type
The first part was reviewed by Steve Mallory.
For the second part, you can use the mapper framework to handle copy values โโfrom one instance to another. Since the names of each type do not match, you need to specify how to match the names (in your example, add "p_" and make it lowercase). One possibility is to fix the mapping .
If you defined the whole community, it would be something like this:
public TResult GetById<TResult, TEntity>(int id) { using (DBEntities dbe = new DBEntities()) { T result = dbe.StoreTables.Set<T>.Find(new object[] {key}); var mapper = ObjectMapperManager.DefaultInstance .GetMapper<TEntity, TResult>( new DefaultMapConfig().MatchMembers((m1, m2) => "p_" + m1.ToLower() == m2)); return mapper.Map(result); } }
Chris pitman
source share