This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hey Guys, let me explain the problem:
I currently have a bunch of objects and in these objects i have a calculation that could easily be done by the database (basically the minimum of a datetime column in a child collection) rather than itterate through the objects and call the calculate method which creates an overhead with lots of db calls to calculate each entities value.. is it possible to have this value returned when i select the objects.. I don't want to update the value ever so it'll be a transient value but would be nice to do this in one hit rather than the potential 100 and without slecting all the date times associated when i do the select.
Any thoughts?
Cheers Owen |
|
|
If you declare the field as readonly then it will be loaded from the database but not saved, e.g.: private readonly int _myDatabaseCalculatedProperty; Obviously this assumes that the calculated data is returned from the query as a column, e.g. via a view or a computed column in the database table. From your description I assume that's the case. If not, then a UDF and a LINQ projection might be the answer -- let me know. |
|
|
Hi Owen, You cant define this using the designer since we dont know much about computed columns up in designer land, but you can easily set this up manually and have the values of computed columns surfaced in your materialized entities by using a readonly field to hold the value. So to get this working, set up your table schema with the computed column; e.g. a contrived example.. CREATE TABLE [dbo].[FoxHunting]( )
You can drag this on to the designer if you want, however you will then need to mod the definition for the TeleportedPeacocks field. To avoid regeneration issues, set the generation of this to be "None" and then implement the definition in a partial class. Your definition for TeleportedPeacocks will be a readonly field and property - e.g. private readonly int _teleportedPeacocks; public int TeleportedPeacocks And you should be good to go from there :) As the field is readonly, LightSpeed wont include this in any create/update statements.
Jeremy |
|