question

technette avatar image
technette asked

Entity SQL Have one function call another

I am working on a solution looping through a table which is a result set with data from multiple systems. I need to update some columns in the table with additional information. I am using Entity Framework 4 and need to know how to correctly have one function call another. The first function gets all employeeids from the table. For each EmployeeID, another function must be called that Adds the FunctionalManager Name to the Table. How do I write this correctly? Public Function GetEmployeeID() As IList(Of Table1) Dim dataContext = New MyEntities() Dim EmployeeIdList = (From n In dataContext.Table1 Select n.EmployeeID).ToList For Each n In EmployeeIdList **strong text**GetManName(EmployeeID) Next Return EmployeeIdList End Function Public Function GetManName(id) Dim dataContext = New MyEntities() Dim ManName = From n In dataContext.Table1 Where n.EmployeeID = id Select n.FunctionalMgrName.FirstOrDefault Return ManName End Function
entity-framework
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Håkan Winther avatar image
Håkan Winther answered
i haven't used Entity framework or VB.NET (only C#), but I'll try to help you anyway What are you going to to with the result of the second function? It looks like you return ManName but you don't take care of the result in the first function. - You need to declare a variable of some type in function1 - Alter your second to return the same type - use your variable to get the result of the function The code should look something like this: Public Function GetEmployeeID() As IList(Of Table1) Dim x AS theDatatype Dim dataContext = New MyEntities() Dim EmployeeIdList = (From n In dataContext.Table1 Select n.EmployeeID).ToList For Each n In EmployeeIdList x=GetManName(EmployeeID) Next Return EmployeeIdList End Function Public Function GetManName(id) AS theDatatype Dim dataContext = New MyEntities() Dim ManName = From n In dataContext.Table1 Where n.EmployeeID = id Select n.FunctionalMgrName.FirstOrDefault Return ManName End Function
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.