|
Assume there is a method which return the query result List<Student>
List<Student> FindStudents(StudentCriteria sc); in which the StudentCriteria is a model for passing the search information:
public class StudentCriteria
{
public string Name { set; get; }
public int? Age { set; get; }
public DateTime? BeginRegisterDate { set; get; }
public DateTime? EndRegisterDate { set; get; }
}
Moveover, we should validate the input parameter StudentCriteria , so we call the following method in FindStudents(...)
ValidationResult Validate(StudentCriteria sc); in which ValidationResult is an object representing the validation result, something like that:
public class ValidationResult
{
public bool Success { set; get; }
public List<String> ErrorInfo { set; get; }
}
All 'Error' information will be contained in ValidationResult and return to FindStudents(...) if Validate(...) finds any problem in StudentCriteria sc :
such as Age is negative int, EndRegisterDate is before BegionRegisterDate...
But, how can FindStudents(...) return the ValidationResult to the caller?
-----Someone may consider that FindStudents(...) throws ArgumentException to the caller if StudentCriteria sc is invalid....
However, I think Exceptions are for exceptional circumstances
|
|
|
|
|
I see no point in "validation" when you're in the "data access / model layer"; all data should have been validated before that.
You return a list; with items or empty (if nothing found / returned). That's it.
(Database server issues are handled in their own layer.)
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
For a start you are not validating the result, you are validating the criteria!
So
ValidateCriteria can return a string (empty if valid else the error info) OR a bool and the method itself informs the user of the error info.
Then if the Criteria is valid pass it to the database for search and if it returns an empty list then there is no such student.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
public class StudentCriteria
{
public string Name { set; get; }
public int? Age { set; get; }
public DateTime? BeginRegisterDate { set; get; }
public DateTime? EndRegisterDate { set; get; }
public ValidationResult Validate ()
{
ValidationResult result = new ValidationResult();
if (Age > 0)
result.ErrorInfo.Add("Nope, too young.");
return result;
}
}
public class ValidationResult
{
public bool Success { get { return Convert.ToString(ErrorInfo).Length > 0; } }
public List<String> ErrorInfo { set; get; }
}
codecs1 wrote: All 'Error' information will be contained in ValidationResult and return to FindStudents No.
You may validate you search-criteria, but "FindStudents" should not be linked to that. Reading from a db has nothing to do with search-criteria. Decouple those. Before calling "FindStudents", confirm and validate your input, before passing to a database.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Thanks for all your replies!! I have gotten the idea that the caller must validate the data first.
But if it is a DLL static method for providing services to the upper presentation layer such as Winform, Webform, Asp.net Mvc, WCF or WPF:
public static List<Student> FindStudents(StudentCriteria sc); The presentation layer has no any idea or logic on the Student and also StudentCriteria .
It just calls the static service using the information such as age or Name to get List<Student>
If you are the developer of such service layer, how do you design the signature of the stateless
method FindStudents(...) ?
(i.e. For the service consumer, All he needs to know is just to call one service and get the data)
modified 14-Mar-21 21:23pm.
|
|
|
|
|
|
Your reply is exactly what I concern and need.
Thanks Richard
By the way, the article provided is too difficult for me
so I need to study more in C# syntax first.
|
|
|
|
|
what is types of Architecturel rendering ?
|
|
|
|
|
|
I'll try to keep the example simple. I am wondering if we should store data differently so that reporting might be easier. For example, let's say we log when a user logs in and out. A normal sql table might look something like this:
user_id | action | log_date |
---|
1 | Login | 2021-01-01 8:00 AM | 1 | Logout | 2021-01-01 5:00 PM
| 1 | Login | 2021-01-02 8:00 AM | 1 | Logout | 2021-01-02 10:00 AM | 1 | Login | 2021-01-02 12:00 PM | 1 | Logout | 2021-01-01 5:00 PM |
So on and so forth.
Let's say the business needs a report of how long each user is logged in each day. I'm pretty sure I could figure out some sql that uses row_number and partitioning and subtract previous value to end up with the difference between each login and logout event and sum for each day. (Ignore night shifts that might start in the evening and run over to the next day.)
However, we don't want to be writing reports but using an ad-hoc report engine, such as PowerBi.
1) Can a reporting engine take the table of data and allow the user to run a report that shows how long each user is logged in each day?
2) As developers, should we store the data differently to make those types of reports easier? Maybe have a separate summary table?
I know PowerBi pretty well but I don't know how to do a report of how long each user is logged in based on just this table of data.
Should we as developers store the data differently, or is it up to the report (BI) side to manipulate the raw data? Thoughts and opinions?
|
|
|
|
|
It's the difference between an "operational" system versus an "informational" system.
Operational / transaction systems are optimized for day-to-day usage.
An informational system (e.g. a "data warehouse" / DW) is designed specifically for info retrieval and could include redundant data to facilitate querying. The data in the info system is extracted from the operational systems.
The operational system may span a year, more or less. The DW could span decades.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
If I understand you correctly, keep logging it the way we are but we may need a separate system (data warehouse) to make reporting easier.
Thanks for the feedback.
|
|
|
|
|
Correct. You may also not want "ad hoc users" hammering the operational system with inefficient queries that impact overall performance of the day-to-day.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
And now it becomes a design issue, do you store the DW data in a denormalised structure (this is standard practice for a DW) do you then write 2 distinct reports targeting each system.
How often do you transfer data to the DW?
How often do you purge data from the production system?
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I have setup consisting of several devices that can communicate through high-speed buses. The following devices exist:
A. 1 grandparent.
B. The grandparent has 5 children. I will denote these the parents.
C. Each parent has 1 child. I will denote these the children.
The grandparent can talk directly to the parents and the parents can talk directly to the grandparent and their own child. Furthermore, the grandparent can also talk to its grandchilden, but it needs to do so via the parent and likewise, the children can talk to the grandparent, but needs to go through its parent. I need to visualize in a table (C# DataGridView) how packets are going back and forth and make it easy to understand what's going on in the system at any given time. All devices has a debug UART and I can modify the source code in all the devices to get the debug messages I need. I'm currently writing a terminal application that can handle several COM ports. I was thinking that the grandparent always logs its data with 0 indentation, parent 1 logs with 4 spaces indentation, parent 2 logs with 8 spaces indentation, etc. Then I was thinking about showing the same packet as it progresses through the chain in the same color everywhere. Whenever a log message contains the word error, then I will display that row in red. If something is purely information, but not a packet, then I was thinking about showing that with a specific pattern style (similar to Excel "Format Cell" -> "Fill" -> "Pattern Style"). Does anybody have any comments or suggestions on this? Is there something I can google image search to get some inspiration?
|
|
|
|
|
I don't know what limitations you face when displaying this, but a message sequence chart[^] might work. I generate simple ASCII versions of them in a session processing framework that I developed, and I was impressed by this article[^], which might help you generate professional looking ones.
|
|
|
|
|
Wow, that's impressive! I'm one layer above, though, so I'm only logging whether it's a read/write and the address and number of registers. I don't log the reply packets, but if I don't get a reply packet then it gets logged as a critical error.
|
|
|
|
|
If the system is idle for long time then can we find this using the mouse movement or mouse click event the system's idle time.
|
|
|
|
|
|
I'm working on a Windows forms application that shows a list of PDFs in a given folder, with a toolbar with buttons that carry out operations on the list of PDFs. The form has a data grid view that takes as its data source a list (PDFlist) of objects (PDFentry) that have properties file name, file date, file size, etc. (Like Windows Explorer).
Because the operations are carried out on the entire list of PDFs, the code for the various operations necessarily loops through PDFlist, acting on each item. That's a lot of code, so form.cs is pretty big (900+ lines). It seemed to me that PDFlist could be its own class, inheriting from List and adding methods for the various operations. Then form.cs would just have a line that said PDFlist.Compress(), or PDFlist.Print(), or whatever the operation was.
But then the red flag was that there's only ever one instance of PDFlist. It's not a singleton in the sense that I don't have to prevent a second instance from being created. It's just that the application only uses one PDFlist throughout.
Would this be a case where a static class is appropriate?
|
|
|
|
|
One thing I have painfully learned is that while a static may work now, at some point you will end up using it from multiple threads and then all hell will break loose. If the class has any state, try not to make is global or thread static.
Also, these types of errors are some of the worse to debug.
"Time flies like an arrow. Fruit flies like a banana."
|
|
|
|
|
RobertSF wrote: Would this be a case where a static class is appropriate? No, a normal class is what would be appropriate. Whether you have one instance of the class or one thousand is irrelevant.
|
|
|
|
|
I have (static) "adapter" classes; similar in concept to a "table adapter" and its "fill" (a table) method, etc.
Static, because often there is no instance data other than the object being operated on. Just makes calls simpler when you don't need a instance reference to an adapter.
Adapters, for me, often make more sense than adding methods to an object, which then operate on "itself".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
|
What is Google[^]?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|