KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm quite new to Entity Framework and I have a question about filtering data. I have two various Log entities, they are: DiskLog and NetworkLog . These entities both are derived from Log entity. Here is some code from my C# app: public class Log { ... } public class DiskLog : Log { ... } public class NetworkLog : Log { ... } public enum LogType { NotInitialized = 0, Disk, Network } public List<Log> GetWithFilter( Guid userKey, int nSkip, int nTake, DateTime dateFrom = DateTime.MinValue, DateTime dateTo = DateTime.MaxValue, LogType logType = LogType.NotInitialized, int computerId = 0) { // need to know how to optimize ... return ... } Of course, I already have working app and database tables created. What I want to do is to make function GetWithFilter work. I have several execution ways there: if logType == LogType.Disk && computerId <= 0 (it means there is no need to use computerId parameter in the query, select DiskLog entities only) if logType == LogType.Disk && computerId > 0 (means I have to use computerId parameter, select DiskLog entities only) if logType == LogType.NotInitialized && computerId <= 0 (no need to use computerId and logType, just select all the entities, DiskLog and NetworkLog) if logType == LogType.NotInitialized && computerId > 0 (select all types of logs for specified computer) if logType == LogType.Network && computerId <= 0 (select all NetworkLog entities) if logType == LogType.Network && computerId > 0 (select all NetworkLog entities for specified computer) As you can see, there are plenty of available options. And I got to write 6 queries li
Tags (comma-separated)
Save Edits
Cancel