Hello Team, I tried binding these tables together and this is the error mesage that came in the screenshot below
public JsonResult UpdateItem(int? ItemId)
{
var dataList = objRestaurantDBEntities.tblItems.Include("tblCategory").Include("tblQuantity").ToList();
var modifiedData = dataList.AsEnumerable().Where(x => x.ItemId == ItemId).Select(d => new bindItem
{
ItemId = d.ItemId,
CategoryId = d.CategoryId,
PCode = d.PCode,
CategoryName = d.tblCategory.CategoryName,
QuantityId = d.QuantityId,
Quantity = d.tblQuantities.Quantity,
ItemName = d.ItemName,
ItemPrice = d.ItemPrice,
Active = d.Active
}).FirstOrDefault();
return Json(modifiedData, JsonRequestBehavior.AllowGet);
}

Ali BenchaabanPosted Jan 5, 2024, 9:09 PM
Based on the provided class definitions, it looks like you have defined the relationships between
tblCategory,tblItem, andtblQuantitycorrectly.The error you mentioned earlier suggests that the LINQ query is not able to find a
QuantityIdproperty intblItem. In yourbindItemclass, you have definedQuantityIdas a property, but it's not clear if you want to map this totblQuantity.QuantityIdor some other property.Here's an updated LINQ query that should help you map the properties correctly:
Make sure to test this updated query and adjust it further based on your specific requirements and business logic.
Regards,
Anandu G NathPosted Jan 6, 2024, 10:18 AM
Check this code
Emmmanuel FIADUFEPosted Jan 6, 2024, 10:15 AM
Thank you team, it is working now
Emmmanuel FIADUFEPosted Jan 5, 2024, 8:10 PM
public partial class tblCategory();
tblItems { get; set; }
{
public tblCategory()
{
this.tblItems = new HashSet
}
public int CategoryId { get; set; }
public string CategoryName { get; set; }
public virtual ICollection
}
public partial class tblItem();
CategoryId { get; set; }
tblQuantities { get; set; }
{
public tblItem()
{
this.tblQuantities = new HashSet
}
public int ItemId { get; set; }
public string PCode { get; set; }
public string ItemName { get; set; }
public decimal ItemPrice { get; set; }
public Nullable
public int Active { get; set; }
public virtual tblCategory tblCategory { get; set; }
public virtual ICollection
public partial class tblQuantity
{
public int QuantityId { get; set; }
public int ItemId { get; set; }
public int Quantity { get; set; }
public virtual tblItem tblItem { get; set; }
}
public class bindItem
{
public int ItemId;
public int? CategoryId;
public string PCode;
public string CategoryName;
public int? QuantityId;
public int Quantity;
public string ItemName;
public decimal ItemPrice;
public int Active;
}
Ali BenchaabanPosted Jan 5, 2024, 7:55 PM
Hello,
The error you're encountering suggests that the
tblItemsclass does not have a property namedQuantityId. This could be due to a typo or because theQuantityIdproperty is not part of thetblItemsentity in your database model.Assuming that
QuantityIdis a valid property in your database model, you should check for the correct naming and casing. If the property is named differently or has a different casing, you need to adjust your LINQ query accordingly.Could you give us your data model used within this code ?
Regard,
BENCHAABAN Ali
Emmmanuel FIADUFEPosted Jan 5, 2024, 6:41 PM
Please the same error still pop u
Sachin SinghPosted Jan 5, 2024, 5:37 PM
Please try this
Emmmanuel FIADUFEPosted Jan 5, 2024, 5:27 PM
Please this is the error that came after applying your code
Sachin SinghPosted Jan 5, 2024, 4:52 PM
try to use this