문제

On the SQL server I create a UDF. Let's name it fnCompanyDetails. It selects some information about a company from several joint tables. I then drag-and-drop this function in the new .dbml of my VB project. I want to use it with LINQ. Smth like this:

Dim company = (From c In d.fnCompanyDetails(sap)

                    Select New With {

        .Sap = c.txtSAP,

        .CompanyName1 = c.txtCompanyName1, _

        .CompanyName2 = c.txtCompanyName2, _

        })

The result of this query I display to the user in a form. If some field is changed I want to send the changes to my database, but is this possible if I'm quering like this, from a UDF? Thank y

도움이 되었습니까?

해결책

No, it is unfortunately not possible to do in a simple way. Linq-to-sql supports reading to custom types, but only support updates through the entity types that exactly corresponds to a table.

Normally the best way is to always read pure entity objects if they are read with the intention to update them.

Another solution is to create entity objects out of the data returned from the udf and then attach those entities to the context. If you attach the entities in their original state first and then make changes after attaching, you should get away without any change tracking problems.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top