Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would absolutely not use WCF purely on the basis of architecture, unless you specifically needed features it provided. I.e. certain transports/protocals to support certain business to business needs. MVC has WebAPI now which is basically same stuff migrated from WCF and made much easier to use, and might meet your architectural needs with much less headache.</p> <p>Additionally, I would not even use WebAPI unless I was exposing a something that I know for sure will be used outside of my application. If this service layer will only be used by this MVC application, then I would do away with it. You can still have a business layer+data layer and maintain separation of concerns without it. That's just my own opinion.</p> <p>Usually I make use of View Models, which are models tailored for the view. They allow me to refactor either the View or the database independently and only have to change the data transformation code. I.e. database field changed might only require a tweak in the query, and the ViewModel stays the same, thus all views using that view model stay the same. Pretty much the same way you are querying and transforming the entities from the query into a <code>new Account</code> except I name mine AccountVM for view model(the <strong>model</strong> specifically for the <strong>view</strong>)</p> <p>I personally call these types of data query/transformation methods from my controller. The controller then just passes the AccountVM or collection to the <code>View(vm)</code> where vm is the name of the variable holding the AccountVM or collection.</p> <p>This is how I get the data from DB to View. The EF entity classes and VM classes are usually pretty similar anyhow, and sometimes identical. I feel like a middle business entity class would be too similar to one or the other to really warrant the extra class and extra copying.</p> <p>So to answer a couple of your questions in my opinion: 1 Yes, basically I think this is a good approach.</p> <p>2 This GetAccountAndItsTraits is called from the Controller and the View is based on your business poco(or what I call ViewModel). So the return from the business layer matches what your model expects. I wouldn't have a service layer here. However, I might instead have some methods dedicated purely to converting EF entities to View Models, which would happen after the business model function is called. In other words, the business model would return EF entities, and then mapping functions would map those to whatever view model is needed in that case, since you could have lots of View Models and Views that utilize that same business method. I use EF Code First, so my entity classes are already pretty close to being POCOs, so it doesn't offend me for them to leak into other layers.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload