views:

162

answers:

1

Just starting out with LINQ to SQL (you can probably tell - be gentle).

I'd like to use the value returned by a user-defined function as an entity class property value and have the the value populated when all the other basic (column) fields are loaded.

I know there are ways to use the UDF from a L2S query (here, and here), but I'd prefer to have the value automatically loaded.

For example, I'd expect LINQ to SQL to generate SQL similar to this and populate a property on my User entity class called AssociatedRecordCount with the integer value returned by GetAssociatedRecordCount:

SELECT ID, dbo.GetAssociatedRecordCount(ID) As AssociatedRecordCount
FROM Users

Also, I'm using the Visual Studio LINQ to SQL designer.

Thank you!

A: 

Try to create a new custom property not associated with the database and call the function (added to the context) in the getter.

Devart
Thanks Devart. What I really want is to have the UDF generated value pre-loaded when I get the entity object from the database as my application will disconnect the object from the datacontext during remoting serialization. But I don't think there's a way to do that and I think your answer is as close as I'll get.
shaunmartin