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.
This issue is corrected after installing the ASP.NET 5 RC1 update.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With