I have table CustomerPurchase and equivalent data class DBML file also created. In this, DBML class, I have added my Custom field 'TotalAmount' for calculations to show in the Listivew. but InsertOnSubmit(), it is throwing an error as Invalid column name 'TotalAmount'.

How can I exclude this user defined field while submit?

有帮助吗?

解决方案

If you look inside the dbml file, you can see it is generate partial classes, so you can some partial classes to your entities, and create other properties, like TotalAmount you need. There you can access other properties and make calculated property, for sample:

namespace YourEntityNameSpace
{
    public partial class CustomerPurchase 
    {
        public double TotalAmount
        { 
            get
            {
                // your code goes here to calculate, for sample:
                return UnitPrice * Amount;
            }
        }
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top