Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Peculiar Issue When Using Expressions and (Web) Console Application

I ran into an issue the other day that I first believed to be an issue with Entity Framework. I posted a question about it the other day here. Since then, I have determined that this issue is not related to Entity Framework.

Consider the following classes:

public abstract class ModelBase
{
  public Guid Id { get; set; }
}

public class User : ModelBase
{
  public string Username { get; set; }
}

public abstract class ModelBaseConfiguration<T> where T : ModelBase
{
  public virtual void Configure()
  {
    ConfigureGuidProperty(e => e.Id);
  }

  protected void ConfigureGuidProperty(Expression<Func<T, Guid>> expression)
  {
    Debug.WriteLine(expression);
  }

  protected void ConfigureStringProperty(Expression<Func<T, string>> expression)
  {
    Debug.WriteLine(expression);
  }
}

public class UserConfiguration : ModelBaseConfiguration<User>
{
  public override void Configure()
  {
    base.Configure();
    ConfigureStringProperty(e => e.Username);
  }
}

If I add the following code to the Main method of an old Console Application project (the one located under the Windows node in VS2015):

UserConfiguration configuration = null;

configuration = new UserConfiguration();
configuration.Configure();

...and execute it, I get the following output in the debug window:

e => e.Id
e => e.Username

This is what I expect.

Now, if I use the exact same code as listed above in a new ConsoleApplication project (the one located under the Web node in VS2015) and execute it, I get the following output in the debug window:

e => Convert(e).Id
e => e.Username

As you can see, the first line of output is different than before. This is what is causing issues with Entity Framework.

I have discovered that the difference is the project type, being that the code is exactly the same in both scenarios. What I am trying to figure out is why. Why is there an attempted conversion in the expression of the second scenario? Is there something I have been missing for some time now? Is this an issue with the new project type? I am trying to educate myself so that I can adjust if necessary.

like image 725
Jason Richmeier Avatar asked Oct 30 '22 15:10

Jason Richmeier


1 Answers

This issue is corrected after installing the ASP.NET 5 RC1 update.

like image 123
Jason Richmeier Avatar answered Nov 09 '22 14:11

Jason Richmeier