Hello, How can I get Dynamic Data to generate a ReadOnly field/column for my Entity? I've seen many folks give the example of a "Total" column that would take Quantity * Price and total it up. The general advice seems to be to "Put it in the database" -
so it gets transfered to the EntityFramework model.. The thing is, what if.. I want to get the data from somewhere else? For example I have a "IT_Server" class that has a computed property of "IsServerOn" and I want to run some code to determine that by..
say pinging the server quickly..
So I'd do something like this:
partial class IT_Servers : IAuditable
{
public class Metadata
{
[ScaffoldColumn(false)]
public object Id;
public object ServerName;
[ScaffoldColumn(true)]
public object IsServerOn;
}
[LazyLoad] // lazy loading would be neat to add later :)
public bool IsServerOn
{
get
{
return VirtualServerSDK.GetPowerState(ServerName);
}
}
}
How do I get it to show on the auto generated List and Edit pages?
You should open SQL Management Studio first and set the default value for the totalColumn。And then for the Total property,plz just mark it with the data annotation——
None
0 Points
6 Posts
CodeFirst(?) Computed Column
Apr 10, 2012 06:40 PM|tsoft|LINK
Hello, How can I get Dynamic Data to generate a ReadOnly field/column for my Entity? I've seen many folks give the example of a "Total" column that would take Quantity * Price and total it up. The general advice seems to be to "Put it in the database" - so it gets transfered to the EntityFramework model.. The thing is, what if.. I want to get the data from somewhere else? For example I have a "IT_Server" class that has a computed property of "IsServerOn" and I want to run some code to determine that by.. say pinging the server quickly..
So I'd do something like this:
How do I get it to show on the auto generated List and Edit pages?
All-Star
94130 Points
18109 Posts
Re: CodeFirst(?) Computed Column
Apr 11, 2012 09:25 PM|Decker Dong - MSFT|LINK
Hello:)
【Solutions】
You should open SQL Management Studio first and set the default value for the totalColumn。And then for the Total property,plz just mark it with the data annotation——
1)[DataBaseGenerateOption(DataBaseGenerateOption.Computed)] (Code first)
2)For db-first,just open your edmx file and then create StoreGeneratedPattern="Identity" for you Total property。
Reguards!