I am currently working on a parking application in Visual Studio using C# language. In the payment form, there are 2 textboxes named tbMembership (which holds the membership ID) and tbRate (which holds the parking fee based on membership and vehicle type), and 1 combobox named cbType (which holds the vehicle type ID).
I have an SQL database for the Payment form called ParkingData, which contains the following fields: id, license_plate, vehicle_id, employee_id, hourly_rates_id, datetime_in, datetime_out, amount_to_pay.
Based on the client's request, the parking fee per hour will vary depending on whether the vehicle belongs to a member or not. Additionally, the calculation is based on the rounded number of hours the vehicle is parked.
I tried to make code like this but it doesn't work
void tarif()
{
var harga = Global.db.HourlyRates.FirstOrDefault(x => x.value == Convert.ToDecimal(tbRate.Text));
harga.vehicle_type_id = Convert.ToInt32(cbType.SelectedValue);
harga.Membership.name = tbOwner.Text;
if (harga != null)
{
tbRate.Text = harga.value.ToString();
}
}
There is an error code in the first line of that code ie recognize the method 'System.Decimal ToDecimal(System.String)' method, and this method cannot be translated into a store expression.'
void tarif()
//in the first line
var harga = Global.db.HourlyRates.FirstOrDefault(x => x.value == Convert.ToDecimal(tbRate.Text));
harga.vehicle_type_id = Convert.ToInt32(cbType.SelectedValue);
harga.Membership.name = tbOwner.Text;
if (harga != null)
{
tbRate.Text = harga.value.ToString();
}
}
1条答案
按热度按时间xxe27gdn1#
and performing the conversion in C# rather than within the LINQ query. Here's an updated version of your code: