Question

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?

Was it helpful?

Solution

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;
            }
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top