Click here to Skip to main content
15,903,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on a ASP.NET MVC 4 with entity Framework 5. I have one NotMapped Property in my model class. When i retrive data for this model, all the data in the list ok except this notmaaped property field. It contains null value in this field.

Below is my Model class

 public class CPUDetail
    {
        public int CPUDetailId { get; set; }
        [Required]
        [Display(Name = "Quantity")]
        public int Qty { get; set; }
        public DateTime CreatedDate { get; set; }
        public int CreatedBy { get; set; }
        public DateTime ChangedDate { get; set; }
        public int ChangedBy { get; set; }

        [Required]
        [Display(Name = "CPU Master")]
        public int CPUMasterId { get; set; }
        public virtual CPUMaster CPUMaster { get; set; }

        [Required]
        [Display(Name = "SubCategory")]
        public int SubCategoryId { get; set; }
        public virtual SubCategory SubCategory { get; set; }

        [NotMapped]
        public string SubCategoryNme { get; set; }
    }

for retrive data code in controller

 public JsonResult GetDetail(int CPUMasterId)
        {
            string str = "";
            CPUDetail cpu = new CPUDetail();
            try
            {
                _list = CPUDetailRepository.GetCPUDetailByCPUMasterId(CPUMasterId).ToList();
                CPUMasterId = 0;
                str = "Success";
            }
            catch (Exception)
            {
                str = "Success";
            }
            return Json(_list, JsonRequestBehavior.AllowGet);
        }

plz have look in this code...


Please reply if any one have proper solution for same.
Posted
Updated 10-Jan-14 18:56pm
v3
Comments
Sampath Lokuge 11-Jan-14 0:36am    
Is this 'accept' or 'Except' ? Can you put your model and also the EF query ?
Bhavesh Jogani IT 11-Jan-14 0:55am    
Below is my Model class

public class CPUDetail
{
public int CPUDetailId { get; set; }
[Required]
[Display(Name = "Quantity")]
public int Qty { get; set; }
public DateTime CreatedDate { get; set; }
public int CreatedBy { get; set; }
public DateTime ChangedDate { get; set; }
public int ChangedBy { get; set; }

[Required]
[Display(Name = "CPU Master")]
public int CPUMasterId { get; set; }
public virtual CPUMaster CPUMaster { get; set; }

[Required]
[Display(Name = "SubCategory")]
public int SubCategoryId { get; set; }
public virtual SubCategory SubCategory { get; set; }

[NotMapped]
public string SubCategoryNme { get; set; }
}

for retrive data code in controller

public JsonResult GetDetail(int CPUMasterId)
{
string str = "";
CPUDetail cpu = new CPUDetail();
try
{
_list = CPUDetailRepository.GetCPUDetailByCPUMasterId(CPUMasterId).ToList();
CPUMasterId = 0;
str = "Success";
}
catch (Exception)
{
str = "Success";
}
return Json(_list, JsonRequestBehavior.AllowGet);
}

plz have look in this code...
Sampath Lokuge 11-Jan-14 1:05am    
Where's the code for 'GetCPUDetailByCPUMasterId' method ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900