I have created an Dynamic data site with ASP.NET, c# and EF(Model first Approach) in which i have some time fields and now i want to add those time fields and display the sum in an textbox which is already available in the model as "Total Time", the
problem here is i couldn't figure out were to write the custom code.........kindly help me with the code if possible.............Thanks in advance
Hi this sort of thing is possible but you have to remember that sort will not work on model based calculated fields I always start database first for this reason and use a computed column.
There was an post on this forum a while back but I don't think he posted his soluttion there :( I woudl podt on the EF forum to get this answer.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
As per your suggestion i created a model with database first appraoch and now the problem is that i can't find those computed columns in dynamic data site, so how can i make those computed columns appear in dynamic data site.
I did that already but still can't see the computed columns in dynamic data site is there anything else i am missing....., i have went through the previous posts and i found this is reply...does this replicates my problem......i am using entity framework
4.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.DynamicData;
namespace Test1
{
[MetadataType(typeof(lstCustomerMetadata))]
public partial class Test1
{
public int t4
{
get
{
//Do calculation on outstanding jobs
return 10;
}
}
}
public class lstCustomerMetadata
{
[ScaffoldColumn(true)]
[UIHint("Text")]
public object t4 { get; set; }
}
}
and i also tried like
[MetadataType(typeof(Invoice_Metadata))]
[ScaffoldTable(true)]
public partial class Test1
{
public class Invoice_Metadata
{
[UIHint("Text")]
[ScaffoldColumn(true)]
[Display(AutoGenerateField=true)]
//[DatabaseGenerated(DatabaseGenerationOption.Computed)]
public object t4 { get; set; }
}
}
in either ways i was unable to get computed columns displayed.
Member
1 Points
13 Posts
Problem writing code with Entities(Asp.net c#,Dynamic Data, Entity Framework)
Jul 19, 2013 09:51 AM|naikotiarun|LINK
Hi
I have created an Dynamic data site with ASP.NET, c# and EF(Model first Approach) in which i have some time fields and now i want to add those time fields and display the sum in an textbox which is already available in the model as "Total Time", the problem here is i couldn't figure out were to write the custom code.........kindly help me with the code if possible.............Thanks in advance
All-Star
17916 Points
5681 Posts
MVP
Re: Problem writing code with Entities(Asp.net c#,Dynamic Data, Entity Framework)
Jul 19, 2013 10:03 AM|sjnaughton|LINK
Hi this sort of thing is possible but you have to remember that sort will not work on model based calculated fields I always start database first for this reason and use a computed column.
There was an post on this forum a while back but I don't think he posted his soluttion there :( I woudl podt on the EF forum to get this answer.
Always seeking an elegant solution.
Member
1 Points
13 Posts
Re: Problem writing code with Entities(Asp.net c#,Dynamic Data, Entity Framework)
Jul 20, 2013 04:50 AM|naikotiarun|LINK
Thanx Steve.....
Member
1 Points
13 Posts
Re: Problem writing code with Entities(Asp.net c#,Dynamic Data, Entity Framework)
Jul 24, 2013 07:58 AM|naikotiarun|LINK
Hi Steve.,
As per your suggestion i created a model with database first appraoch and now the problem is that i can't find those computed columns in dynamic data site, so how can i make those computed columns appear in dynamic data site.
Thanks in advance
All-Star
17916 Points
5681 Posts
MVP
Re: Problem writing code with Entities(Asp.net c#,Dynamic Data, Entity Framework)
Jul 24, 2013 08:04 AM|sjnaughton|LINK
you have to manyally scaffold those column i.e.
[ScaffoldColumn(true)]
or
[Display(AutogenerateField=true)]
Always seeking an elegant solution.
Member
1 Points
13 Posts
Re: Problem writing code with Entities(Asp.net c#,Dynamic Data, Entity Framework)
Jul 24, 2013 08:45 AM|naikotiarun|LINK
Hi steve.,
I did that already but still can't see the computed columns in dynamic data site is there anything else i am missing....., i have went through the previous posts and i found this is reply...does this replicates my problem......i am using entity framework 4.0
sjnaughton
All-Star
<div class="post-rating All-Star" title="27478 Points"></div>27478 Points
5504 Posts
MVP
<div class="comment-right-col">Re: Computed Column dose not appear in grid
08-24-2008 10:38 PM|LINK
<div>I've just replicated the results with EF.
So the issue appears to be with EF as scaffolded conputed columns do NOT appear to work with EF but do with Linq to SQL
Hope this helps [:D]
</div> </div>All-Star
17916 Points
5681 Posts
MVP
Re: Problem writing code with Entities(Asp.net c#,Dynamic Data, Entity Framework)
Jul 24, 2013 09:10 AM|sjnaughton|LINK
Post a sample of your metadata/buddy class where you have this set do I can look.
Always seeking an elegant solution.
Member
1 Points
13 Posts
Re: Problem writing code with Entities(Asp.net c#,Dynamic Data, Entity Framework)
Jul 24, 2013 09:40 AM|naikotiarun|LINK
The sample is as follows
All-Star
17916 Points
5681 Posts
MVP
Re: Problem writing code with Entities(Asp.net c#,Dynamic Data, Entity Framework)
Jul 24, 2013 01:03 PM|sjnaughton|LINK
Sorry columns computed on the server won't work you will need to remove that code and do the compute in the DB
Always seeking an elegant solution.