Answered by:
Method with two classes as parameters

Question
-
Hi,
how can I write a method that uses classes (T Generic class with Context class)?
I have two classes:class Reminders { [Key] public int ReminderId { get; set; } public string ReminderContent { get; set; } } class RemindersContext : DbContext { /* Rest of the code */ } class HistoryReminders { [Key] public int HistoryId { get; set; } public int ReminderId { get; set; } public string ReminderHistoryContent { get; set; } } class HistoryContext : DbContext { /* Rest */}
I would like to get data by primary key using one method.
I have this method, but I want to avoid copy and paste of the code for another class:
static List<HistoryReminders> GetDataHistoryRemindersById(int rowId) { var list = new List<HistoryReminders>(); using (var ctx = new HistoryContext()) { // for speed up ctx.Configuration.ProxyCreationEnabled = false; foreach (var item in ctx.DbHistoryReminders) { if (item.HistoryId == rowId) { list.Add(new HistoryReminders { HistoryId = item.HistoryId, ReminderId = item.ReminderId, ReminderHistoryContent = item.ReminderHistoryContent, DateReminderExecuted = item.DateReminderExecuted }); } } } return list; }
One more question is - is it a good practice to create a such method and classes as a parameters?
- Moved by litdev Wednesday, October 3, 2018 11:33 PM
Wednesday, October 3, 2018 10:52 AM
Answers
-
I'd probably ask for help over here.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=vslanguages
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Richard MuellerMVP Thursday, October 4, 2018 12:38 AM
- Marked as answer by Richard MuellerMVP Wednesday, October 10, 2018 12:48 PM
Wednesday, October 3, 2018 11:47 PM
All replies
-
This is no Small Basic. You should search for another forum.
Jan [ WhTurner ] The Netherlands
Wednesday, October 3, 2018 3:43 PM -
I'd probably ask for help over here.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=vslanguages
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Richard MuellerMVP Thursday, October 4, 2018 12:38 AM
- Marked as answer by Richard MuellerMVP Wednesday, October 10, 2018 12:48 PM
Wednesday, October 3, 2018 11:47 PM -
Thanks for suggestion.
Moved.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/2e02c3fe-90b3-43ef-999e-f41350b8b41a/method-with-two-classes-as-parameters?forum=csharpgeneralShould I delete this post here?
- Edited by bobis123 Thursday, October 4, 2018 8:31 AM P
Thursday, October 4, 2018 8:24 AM -
Sounds good, you're welcome.
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.Thursday, October 4, 2018 12:40 PM