Answered by:
problem to pass data between layers

Question
-
Hi All.
I have multiple layers solution. The Data Layer has Entity Framework Model1 with Employee class table. In this layer I created EmployeeFactory class with GetEmployees() method.
public static List<Employee> GetEmployees() { var context = new Model1()); return employeedg = context.Employees.AsNoTracking.ToList(); }
The Busyness Layer has Data Layer reference. And in this layer created class EmployeeAdapter with method
public static List<Employee> GetEmployees() { return EmployeeFactory.GetEmployees(); }
The UI Layer has Busyness Layer reference. And to populate WPF DataGrid I created method
public void SetEmployee_DG() { var employees = EmployeeAdapter.GetEmployees(); Employee_DG.ItemsSource = employees; }
But EmployeeAdapter.GetEmployees() display error and point to add Data Layer reference to UI Layer that I don't want to do.
How to solve this problem? Thanks.
- Edited by zleug Saturday, August 8, 2020 12:28 AM
Saturday, August 8, 2020 12:03 AM
Answers
-
Hi DA924x. Thanks for reply.
My knowledge in EF and multi-layer programming is very beginner. If it is possible can you show me code to solve the problem?
Thanks.
- Marked as answer by zleug Thursday, August 20, 2020 12:14 PM
Saturday, August 8, 2020 6:40 PM
All replies
-
What is the error exactly ?
Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
NuGet BaseConnectionLibrary for database connections.
Saturday, August 8, 2020 12:39 AM -
Hi Karen. Thanks for reply.
The error is
The type 'Employee' is defined in an assembly that is not referenced. You must add a reference to assembly 'Employee.DL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.Thanks
Saturday, August 8, 2020 1:09 AM -
You should be passing a DTO through the layers not the EF entity that should be left at the DAL, becuase otherwise, you would have to set reference to the DAL where the EF model is located setting refernce in the PL project to the DAL.
https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp
Here is a 3 layers Windows form project that is using the DTO pattern, and it is also using the DAO pattern in the DAL. The DTO(s) are kept in the classlib project called Entities that is referenced by the 3 layers.
https://javarevisited.blogspot.com/2013/01/data-access-object-dao-design-pattern-java-tutorial-example.html
Saturday, August 8, 2020 5:44 AM -
Hi DA924x. Thanks for reply.
My knowledge in EF and multi-layer programming is very beginner. If it is possible can you show me code to solve the problem?
Thanks.
Saturday, August 8, 2020 6:28 PM -
Hi DA924x. Thanks for reply.
My knowledge in EF and multi-layer programming is very beginner. If it is possible can you show me code to solve the problem?
Thanks.
- Marked as answer by zleug Thursday, August 20, 2020 12:14 PM
Saturday, August 8, 2020 6:40 PM