Click here to Skip to main content
15,886,667 members
Home / Discussions / C#
   

C#

 
AnswerRe: TcpListener don't send FIN after client send FIN Pin
Gerry Schmitz1-Apr-16 7:02
mveGerry Schmitz1-Apr-16 7:02 
GeneralRe: TcpListener don't send FIN after client send FIN Pin
Aurélien381-Apr-16 10:38
Aurélien381-Apr-16 10:38 
QuestionMulti threading with datatable in C# Pin
Jaimesh.24111-Apr-16 3:03
Jaimesh.24111-Apr-16 3:03 
GeneralRepost Pin
Sascha Lefèvre1-Apr-16 3:39
professionalSascha Lefèvre1-Apr-16 3:39 
QuestionFont error when using C# code behind to export from crystal report to pdf Pin
botngot8331-Mar-16 21:55
botngot8331-Mar-16 21:55 
AnswerRe: Font error when using C# code behind to export from crystal report to pdf Pin
Eddy Vluggen1-Apr-16 1:36
professionalEddy Vluggen1-Apr-16 1:36 
GeneralRe: Font error when using C# code behind to export from crystal report to pdf Pin
botngot833-Apr-16 22:05
botngot833-Apr-16 22:05 
QuestionIssue around converting Expression<Func<T, bool>> to Expression<Func<U, bool>> Pin
RichardGrimmer31-Mar-16 3:36
RichardGrimmer31-Mar-16 3:36 
I'm in the process of breaking the link we currently have between EF and our application code. In order to do this, I've created a collection of "Domain" objects to match our "Database" objects, so I have an Entity Framework Account type, and a Domain Account type, both of which have the same fields, notably an int AccountId field.

I've also implemented a simple repository to allow us to pull domain objects. The issue I'm having is I my Find method - the prototype of which is;

Find(Expression<Func<Domain.Account, bool>> predicate)


Obviously, this method deals with domain objects. However, in the EF specific implementation of the repo I'm working on, I can't simply apply the same predicate to a Where() since the predicate refers to domain types rather than database types.

To that end, I've been looking at the ExpressionVisitor class in order to "mutate" the expression into one that deals with database types. Since I want to change the Parameter, I've created the following implementation;

 public class ExpressionParameterModificationVisitor<TTo> : ExpressionVisitor
 {
    public Expression Modify(Expression expression)
    {
        return this.Visit(expression);
    }

    protected override Expression VisitParameter(ParameterExpression expression)
    {
        return Expression.Parameter(typeof (TTo));
    }  
} 


This appears to work as intended (based on examining what I get and my *limited* understanding of this), however, when I attempt to use it;

Expression<Func<Domaain.Account, bool>> predicate = account => account.AccountId == 1;


I'm seeing the error;

Additional information: Property 'Int32 AccountId' is not defined for type 'Data.Account'


The Data.Account type definitely has the correct field, so I'm assuming I need to do more with my Visitor, and override another method - the obvious suspect is to do the following;

protected override Expression VisitMember(MemberExpression node)
{
    return Expression.MakeMemberAccess (base.Visit(node.Expression), typeof(TTo).GetProperty(node.Member.Name));
}


Now the issue I'm seeing is that the VisitMember method is called before the VisitParameter method, and hence I'm getting;

ParameterExpression of type 'Data.Account' cannot be used for delegate parameter of type 'Domain.Account'


Perhaps I'm approaching the issue incorrectly, but anyone have any ideas what I'm missing here?
C# has already designed away most of the tedium of C++.

AnswerRe: Issue around converting Expression<Func<T, bool>> to Expression<Func<U, bool>> Pin
Richard Deeming31-Mar-16 4:59
mveRichard Deeming31-Mar-16 4:59 
GeneralRe: Issue around converting Expression<Func<T, bool>> to Expression<Func<U, bool>> Pin
Sascha Lefèvre31-Mar-16 5:21
professionalSascha Lefèvre31-Mar-16 5:21 
GeneralRe: Issue around converting Expression<Func<T, bool>> to Expression<Func<U, bool>> Pin
Richard Deeming31-Mar-16 5:49
mveRichard Deeming31-Mar-16 5:49 
GeneralRe: Issue around converting Expression<Func<T, bool>> to Expression<Func<U, bool>> Pin
Sascha Lefèvre31-Mar-16 6:41
professionalSascha Lefèvre31-Mar-16 6:41 
QuestionUsing Deployment Item with Directory.GetFiles Pin
RamboSp31-Mar-16 2:17
RamboSp31-Mar-16 2:17 
AnswerRe: Using Deployment Item with Directory.GetFiles Pin
Eddy Vluggen1-Apr-16 1:33
professionalEddy Vluggen1-Apr-16 1:33 
Questioncurrent state of old issue of Enum boxing when used as Keys in a Dictionary ? Pin
BillWoodruff31-Mar-16 2:15
professionalBillWoodruff31-Mar-16 2:15 
AnswerRe: current state of old issue of Enum boxing when used as Keys in a Dictionary ? Pin
Richard Deeming31-Mar-16 2:52
mveRichard Deeming31-Mar-16 2:52 
QuestionMessage Removed Pin
31-Mar-16 0:25
PomegranateTiger31-Mar-16 0:25 
QuestionSync SQLite with Oracle or Postgre Pin
Potestas30-Mar-16 21:42
Potestas30-Mar-16 21:42 
AnswerRe: Sync SQLite with Oracle or Postgre Pin
Nathan Minier31-Mar-16 1:26
professionalNathan Minier31-Mar-16 1:26 
QuestionC# Tic Tac Toe "Simulator" Pin
Member 1242680830-Mar-16 11:24
Member 1242680830-Mar-16 11:24 
AnswerRe: C# Tic Tac Toe "Simulator" Pin
Sascha Lefèvre30-Mar-16 17:15
professionalSascha Lefèvre30-Mar-16 17:15 
AnswerRe: C# Tic Tac Toe "Simulator" Pin
Rob Philpott30-Mar-16 23:41
Rob Philpott30-Mar-16 23:41 
AnswerRe: C# Tic Tac Toe "Simulator" Pin
Patrice T31-Mar-16 0:55
mvePatrice T31-Mar-16 0:55 
RantREPOST Pin
Richard Deeming31-Mar-16 1:42
mveRichard Deeming31-Mar-16 1:42 
QuestionDynamically close DB2 CLP window using C# Pin
Tej_dev30-Mar-16 6:44
Tej_dev30-Mar-16 6:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.