English 中文(简体)
采用外部参数的实体框架习俗财产
原标题:Entity Framework Custom Property using external Parameters

我有一个用于在“DAL”项目中收回一批“推广”实体的EDM。 MVC网站项目参考资料,直接检索目标内容,并将之退回到产品制作和展示网站。

为了简化事情,我们只说有“ID”、“Rate”和“Description”性质。 我想创造另一个称为“CostPerMonth”的计算财产,从称为“LoanAmount”的网站获取信息,并且为了保持简单,这种“CostPer Month”财产将由(“LoanAmount” *“Rate”)/12组成。

我可以提供帮助,但认为应当在数字项目中进行这一计算,以便使该代码更加可重新使用,因为只要使用这一数据,总是会具体规定“LoanAmount”。 我可能的解决办法如下:

  • 创建产品部分类别,在产品中添加新的“CostPer Month”。 在网站控制器中,当数据被退回时,通过回收数据和进行计算,将这一新栏集中起来?

  • 创建产品部分类别,在产品中添加新的“CostPer Month”。 在“DAL”项目中,创立了一个“LoanAmount”参数和清单回归方法的助手班。 问题在于,为了进行计算,我需要实现数据。 这种方法可以接受一种“Skip”和“Take”参数,可在用于返还产品的Linq询问中使用?

  • 创建产品部分类别,在产品中添加新的“CostPer Month”。 在服务方法中,使用WCF网络服务添加另一个层次的解决办法是计算和利用REST将数据退回MVC网站?

任何建议都会受到高度赞赏。

最佳做法

标记

最佳回答

If we take a step back and actually breakdown what you are asking in your question it might be easier to explain my answer.

  • We have an object/entity named Products
  • There is a calculated field which will be (("LoanAmount" * "Rate") / 12)
  • CostPerMonth does not need to be stored in the database

So this calculated field is a business rule for the Product Entity. Given that you are using MVC, there is only one place where this code/logic can go and that is the model.

鉴于你使用EF 它将在一个未规划/投入的领域开展工作,而守则将给你这样的想法。

   [NotMapped]
    public decimal CostPerMonth
    {
        get { return (LoanAmount * Rate)/12 ; }
    }

几天后,我可以谈谈在不同层面分散业务逻辑的问题。

现在,如果你希望其他客户能够轻松地消费这一逻辑,那么你就必须揭露这种服务。 (青年可以使用网络API/服务站/轮椅等),这确实是另一个基于你们需要的问题。 但这里的一点是,你的逻辑是一点。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签