-
Notifications
You must be signed in to change notification settings - Fork 0
ASP.Net (4.7) EF6
jayoungers edited this page Oct 19, 2018
·
4 revisions
The ASP.Net (4.7) EF6 example should contain everything needed to start an EF6 based project with PatchMap, including some additional recommended code to get your API up and running.
EF6AspNetWebApi.sln
contains the following projects:
-
EF6AspNetWebApi.Data
- Entity Classes -
EF6AspNetWebApi
- Business Logic-
Application
- Used to initialize the SQL Context and Serilog logging for the front end applications (i.e. the REST API, the test apps, etc). -
BaseCommand
- Filtering and helper functions intended for use in your commands.-
EnsureExists
- If the passed in argument is null, this will throw anItemNotFoundException
. This is an easy way to short-circuit your business logic for situations that should not occur (i.e. a consumer is using the wrong ids). The REST API is wired up to respond with 404 anytime this exception is thrown. -
FilterToList
&FilterToFirstOrDefault
- simple querying helpers that include LinqKit'sAsExpandable()
to ensure your maps are handled correctly by EF6.
-
-
BasePatchCommand
- an extension ofBaseCommand
that sets up aPatchMap.Mapper
for a given type. This also contains the EF6 specific mapper hooks. -
BasePatchContext
- In our example we will assume allPatchCommands
will use this class or extend it. This Base version contains the DbContext, whether the entity is new, and a collection of validation results that may occur during processing. That should be all that's needed in most scenarios. -
PatchCommandResult
- ourPatchCommands
will all return this type as a result. In our REST API, we'll include a filter that can respond appropriately when it sees this type returned (i.e. 201/200/400/etc).
-
-
EF6AspNetWebApi.Tests
- Business Logic Tests- For any code that's added or modified in the business logic project, there should be a corresponding test here.
-
EF6AspNetWebApi.Web
- REST Web API-
Controllers\BlogsController
- This is what a standard entity controller would look like to handle Searching, Getting, Inserting, Updating, and Patching. -
Filters\ItemNotFoundExceptionFilterAttribute
- return404
anytime this exception is thrown. -
Filters\JsonPatchParseExceptionFilterAttribute
- return400
anytime a consumer/developer passes in an invalid JSON patch. -
Filters\PatchCommandResultFilterAttribute
- respond with 201 or 200 for successful patches and 400 for those that resulted in validation results -
Handlers\ODataResultHandler
- if this was an OData call and the consumer requested a$count
, include that count as a response header -
Handlers\VersionHandler
- For all API Responses we will respond with the version of the project's assembly. This can be a useful key on the UI to determine if the user should refresh the application. -
Swashbuckle/*
- Filters to ensure our API shows up correctly in the swagger documentation
-
-
EF6AspNetWebApi.Web.Tests
- REST Web API Tests- All controller methods should be tested here: the website must be running in order for them to work. You'll want to verify the methods are working, the query string parameters are working, and likely authentication/authorization as well
Concepts
PatchMap Library
Examples