3.0.0.3 دون سرعة الصوت | SimpleRepository | صيغة الملكية / حقل
سؤال
وأحتاج لإضافة صيغة الملكية / ميدانية على دون سرعة الصوت | SimpleRepository فهل يمكن أن تقولوا لي كيف؟ أم أنه ليس من الممكن؟
ور، لا الجسم
المحلول
وأضيف [SubSonicIgnore] إليها أعلاه LineCost
وهكذا
[SubSonicIgnore]
public decimal LineCost
{
get { return Qty * Convert.ToDecimal(LineCost); }
}
وهذا يحدث كما يتم تعيين LineCost إلى قاعدة البيانات.
نصائح أخرى
لماذا لا تفعل الحساب ضمن تعريف الكائن نفسه؟
وهكذا
public class OrderLine
{
public int OrderId { get; set; }
public int Qty { get; set; }
public decimal ProductPrice { get; set; }
public decimal LineCost
{
get { return Qty * Convert.ToDecimal(LineCost); }
}
}
وأستطيع أن أرى مجرد وسيلة باستخدام أنواع مجهولة، ومن ثم سيكون لديك لتحويل نوع إلى سطر الطلب (ليست لطيفة جدا)
var x =from o in repo.All<OrderLine>()
select new
{
OrderId = o.OrderId,
ProductPrice = o.ProductPrice,
Qty = o.Qty,
LineCost = o.ProductPrice * o.Qty
};
List<OrderLine> orders = null;
foreach (var t in x)
{
orders.Add(new OrderLine
{
LineCost = t.LineCost,
OrderId = t.OrderId,
ProductPrice = t.ProductPrice,
Qty = t.Qty
});
}
لا تنتمي إلى StackOverflow