locked
Problem writing code with Entities(Asp.net c#,Dynamic Data, Entity Framework) RRS feed

  • Question

  • User1160430963 posted

    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

    Friday, July 19, 2013 9:51 AM

Answers

  • User-330204900 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 19, 2013 10:03 AM

All replies

  • User-330204900 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 19, 2013 10:03 AM
  • User1160430963 posted

    Thanx Steve.....

    Saturday, July 20, 2013 4:50 AM
  • User1160430963 posted

    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

    Wednesday, July 24, 2013 7:58 AM
  • User-330204900 posted

    you have to manyally scaffold those column i.e.

    [ScaffoldColumn(true)]

    or

    [Display(AutogenerateField=true)]

    Wednesday, July 24, 2013 8:04 AM
  • User1160430963 posted

    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

    sjnaughton

    All-Star

    27478 Points

    5504 Posts

    MVP

    Re: Computed Column dose not appear in grid

    08-24-2008 10:38 PM|LINK

    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]

    Wednesday, July 24, 2013 8:45 AM
  • User-330204900 posted

    Post a sample of your metadata/buddy class where you have this set do I can look.

    Wednesday, July 24, 2013 9:10 AM
  • User1160430963 posted

    The sample is as follows

    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.

    Wednesday, July 24, 2013 9:40 AM
  • User-330204900 posted

    Sorry  columns computed on the server won't work you will need to remove that code and do the compute in the DB

    Wednesday, July 24, 2013 1:03 PM