A particular problem when using expressions and (web console application)

The other day, I ran into a problem that I first considered a problem with the Entity Framework. I posted a question about this the other day here . Since then, I have decided that this problem is not related to the 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 that is 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 same code as above in the new ConsoleApplication project (the one 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 from the previous one. This causes problems with the Entity Framework.

I found that the difference is the type of project, because the code in both scenarios is exactly the same. I'm trying to find out why. Why is there a conversion attempt in the expression of the second script? Is there something that I have long lost? Is this a problem with a new type of project? I try to educate myself so that I can adapt if necessary.

+5
source share
1 answer

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

+2
source

Source: https://habr.com/ru/post/1235915/


All Articles