Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a dbcontext query to a MySql database using EF Core 2 fetching from my usermaster table.

My usermaster inherits from IdentityUser so that I can take advantage of .NET Core's user security features.

But I do not implement all columns in my child class. e.g. Email which is on PersonMaster because while all users are people not all people will be users.

The autogenerated select statement arising from this snippet is pulling in columns from both the parent and child classes
CUserMasterLocal dbEntry = context.UserMaster
          .FirstOrDefault(u => u.p_Username == user.p_Username);


How do I restrict it to just pull from the child class?

What I have tried:

I have tried implementing one of the columns that is not required in the child class with the
[NotMapped]
attribute. It had no effect.

Later today I will try something like this:[^] to see if it delivers for me.

Regardless of this issue it looks like good practice, because if my Oracle days taught me anything all those years ago, surplus columns in a select kill performance.
Posted
Updated 18-Sep-18 22:10pm
v2
Comments
Maciej Los 19-Sep-18 3:58am    
Is there any problem to write custom select statement?
var myData = context.UserMaster
          .Where(u => u.p_Username == user.p_Username)
          .Select(x => new {whatever_you_want});
Ger Hayden 19-Sep-18 4:15am    
Hi Maciej, I will be trying that this evening (once I get the day job out of the way). I have only just learned that this is possible.
ZurdoDev 19-Sep-18 8:58am    
Looks like a solution to me.
Maciej Los 19-Sep-18 9:10am    
Let's find out ;)
Ger Hayden 19-Sep-18 13:02pm    
Its a solution! Put it in the Solution box so that I can accept and rate it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900