<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kieran Gillibrand on Medium]]></title>
        <description><![CDATA[Stories by Kieran Gillibrand on Medium]]></description>
        <link>https://medium.com/@kieran.gillibrand?source=rss-c6bf91c383ad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yRBMLz6gnjLBbf26FIjFzw.jpeg</url>
            <title>Stories by Kieran Gillibrand on Medium</title>
            <link>https://medium.com/@kieran.gillibrand?source=rss-c6bf91c383ad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:01:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kieran.gillibrand/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating a .Net Core REST API — Part 4: Extras]]></title>
            <link>https://medium.com/@kieran.gillibrand/creating-a-net-core-rest-api-part-4-extras-fbd337aaf067?source=rss-c6bf91c383ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbd337aaf067</guid>
            <category><![CDATA[aspnetcore]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[net-core]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Kieran Gillibrand]]></dc:creator>
            <pubDate>Thu, 17 Jan 2019 05:43:38 GMT</pubDate>
            <atom:updated>2019-11-19T04:10:53.930Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating a .Net Core REST API — Part 4: Extras</h3><p><a href="https://medium.com/@kieran.gillibrand/creating-a-net-core-rest-api-part-3-finishing-our-controller-2caa77771be6">Last time</a> we finished up our basic API implementation. At that point we were done the tutorial but I figured I’d add some tips and links that could be useful.</p><h3>Better Unhandled Exception Responses</h3><p>When your application is running in development mode unhandled exceptions will produce an ASP.Net error page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*waQa-CgYXVMunK874DW3qg.png" /><figcaption>Looks really pretty, but this in in a browser…</figcaption></figure><p>You may have realized that as an API response this is a mass of HTML and CSS so it isn’t all that consumable. What if we could install our own handler for all unhandled exceptions?</p><p>Through ASP.Net Core <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-2.2">Middleware</a> we can override the default behavior with our own. My implementation is a class called JsonUnhandledExceptionMiddleware which is heavily borrowed from this <a href="https://stackoverflow.com/questions/38630076/asp-net-core-web-api-exception-handling">StackOverflow post</a>. We simply register the middleware and it handles things from there based on the Accept header and whether we’re running in Development or Production.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*kX1UBf5Cx1PDZqys1a3Sxw.png" /><figcaption>Middleware is registered in the Configure method of Startup.cs</figcaption></figure><h3>Validate Models Automagically</h3><p>You may have noticed our API simply accepts a Post object from POST or PUT requests and blindly inserts or updates it. Real world APIs will likely need some validation.</p><p>You may have noticed earlier that our database modelling generated validation attributes based on properties of the database columns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*vrPPu9LJkK8LFVAaNt8ABA.png" /><figcaption>The Name property of a Post has inherited the Required (NOT NULL) and max length (VARCHAR(200)) attributes from the database.</figcaption></figure><p>In our controller we can validate a model against these attributes using the ModelState.IsValid property. The catch is you have to remember to always do this and then return an appropriate response. What if we could do this in one spot and give a reasonable error message in the response?</p><p>We can use ASP.Net Core <a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-2.2">Filters</a> to do this which are somewhat like Middleware but <a href="https://stackoverflow.com/questions/42582758/asp-net-core-middleware-vs-filters">run in the context of MVC as opposed to the HTTP level</a>. My filter implementation is a class called ValidateModelAttribute and borrowed from <a href="https://blog.cloudhub360.com/returning-400-bad-request-from-invalid-model-states-in-asp-net-94275fdfd2a0">a blog post</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*0lwSbzMLpKrwJ-KVeqJJ2A.png" /><figcaption>We register our filters with the MvcOptions parameter to AddMvc in the ConfigureServices method of Startup.cs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*cmoPvxXA8QIcRuWlHaO4Tg.png" /><figcaption>Our filter checks if the ModelState is valid and extracts validation messages to send with an HTTP 400 error if not</figcaption></figure><h3>API Documentation</h3><p>Producing documentation for your API can be pretty important. <a href="https://www.nuget.org/packages/swashbuckle.aspnetcore/">Swashbuckle</a> is a library for ASP.Net Core that can generate <a href="https://swagger.io/docs/specification/about/">OpenAPI </a>documentation from your API controllers. Swashbuckle can pull information about your API through C# documenting comments as well as attributes on your controller methods.</p><p>I found the <a href="https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-2.2&amp;tabs=visual-studio">Microsoft tutorial</a> really helpful for getting started with Swashbuckle.</p><h3>Reverse Proxying</h3><p>ASP.Net Core applications run on servers called IIS (Windows only) or Kestrel (cross platform). Kestrel is enough to run your API standalone but there can be advantages to putting a traditional web server like Nginx or Apache in front of it as a reverse proxy. These servers can handle HTTPS termination as well as implement compression and other features for your API.</p><p>Microsoft has tutorials for reverse proxying using <a href="https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-2.2">Nginx </a>or <a href="https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-2.2">Apache</a>.</p><h3>Deployment</h3><p>At some point you’ll probably have to build and deploy your API for non-development usage. I simply use the Visual Studio publish feature to publish to my Ubuntu server over <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-vsftpd-for-a-user-s-directory-on-ubuntu-16-04">SFTP</a>. Alternatively you can deploy the application package locally and use another method like SCP to get it where it needs to go.</p><p>If you’re hosting on Windows or Azure you may be able to use Visual Studio’s Web Deploy but I have less experience in that area.</p><h3>Conclusion</h3><p>Thanks for reading! The source for for this part is available on <a href="https://github.com/kgillibrand/Database-First-ASP.Net-Core/releases/tag/4.0">GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbd337aaf067" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a .Net Core REST API — Part 3: Finishing our Controller]]></title>
            <link>https://medium.com/@kieran.gillibrand/creating-a-net-core-rest-api-part-3-finishing-our-controller-2caa77771be6?source=rss-c6bf91c383ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/2caa77771be6</guid>
            <category><![CDATA[net-core]]></category>
            <category><![CDATA[aspnetcore]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[csharp]]></category>
            <dc:creator><![CDATA[Kieran Gillibrand]]></dc:creator>
            <pubDate>Wed, 16 Jan 2019 05:15:11 GMT</pubDate>
            <atom:updated>2019-11-19T04:12:14.745Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating a .Net Core REST API — Part 3: Finishing our Controller</h3><p><a href="https://medium.com/@kieran.gillibrand/creating-a-net-core-rest-api-part-2-controller-setup-8f71408d8f4e">Last time</a> we got our database connection configured for the API itself and created a simple GET handler. This time we’ll create the other handlers for simple POST (create), PUT (update), and DELETE operations.</p><h3>Tweaks</h3><p>Since last time I’ve removed the author information from the GET response. The JSON ended up being a little ridiculous since the author would pull a whole ton of related info. I’ll look into a solution but for now without the Include(...) call for authors our GET handler looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*i9DQc_O0hJX1Ct2qA2IK7A.png" /><figcaption>The Include(…) call for Post.Author has been removed</figcaption></figure><p>Additionally I had to add on delete cascadeto my foreign keys so that related information would be properly removed in my DELETE handler. These changes are reflected in the SQL create script below. Please note that this change affects the content of BlogContext so you will need to remodel after running this script.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/477b4b8538de8871bbd0914f428a7945/href">https://medium.com/media/477b4b8538de8871bbd0914f428a7945/href</a></iframe><h3>POST</h3><p>The HTTP verb POST is generally used by REST APIs to create a new instance of something. Here it will accept a payload of JSON in the request body representing a new Blog post and any associated comments. Then this handler will insert that post into our database.</p><p>First we need to actually create the handler in our PostsController :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*Hlyh3GNkDj1cPSlVNp44bQ.png" /><figcaption>It’s only a few lines! (for now…)</figcaption></figure><p>Our handler receives the post as a parameter from the request body using the [FromBody]attribute similar to the[FromQuery] attribute we saw last time. The post is automatically parsed from JSON including relevant related attributes like the comments.</p><p>We then simply add the post to the DBContext Postscollection. The DBContext tracks changes to these collections and the objects in them so calling SaveChanges flushes this change to the database. After that we return an OKResult since our insert was successful.</p><h3>PUT</h3><p>The HTTP verb PUT is generally used by REST APIs to update an existing instance of something. Here it will update an existing post, overwriting it’s values with new ones from the request body.</p><p>So now we can add our PUT handler:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*g1zK5ov5b7_E40nwt4EIRQ.png" /><figcaption>A few more lines this time</figcaption></figure><p>Our handler accepts a post with new content from the request body and an ID for the post that will be updated from the request URL. We use the Find method to get the existing post with this ID which is just shorthand for running a query with the primary key for the table.</p><p>Then if the existing post was found we set the post values from the new content and flush the changes to the DB.</p><h3>DELETE</h3><p>Delete is fairly self explanatory and quite easy to implement. We will accept the Post ID to delete in the URL but no request body is needed.</p><p>For our handler:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*hn4XlaqInCjVJPjUJ0QeZw.png" /><figcaption>And that’s it!</figcaption></figure><p>We simply find the post with the provided ID (if it exists) and then remove it. Our on delete cascadeat the database level handles removing the related comments.</p><h3>Testing</h3><p>Now we can test our API handlers</p><p>For POST and PUT we simply send some JSON content representing a Post. Then we can verify the results with GET later on. The JSON structure is the same as what you get from the GET response but you can omit DB primary keys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*QSyVObfD0z7Gz1miPdMMag.png" /><figcaption>POST request in Postman</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*MviZYQK_KX_1eBA0IfRODA.png" /><figcaption>PUT request in Postman. Note we need to specify the Id of the post we’re updating in the request URL</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*fiiQwfGr8Iufu1VAN94nrg.png" /><figcaption>And finally a DELETE request in Postman</figcaption></figure><h3>Conclusion</h3><p>So it’s not the fanciest thing ever but we’ve got a simple CRUD API. As usual the source for this tutorial is on <a href="https://github.com/kgillibrand/Database-First-ASP.Net-Core/releases/tag/3.0">Github</a>.</p><p>I’ve written <a href="https://medium.com/@kieran.gillibrand/creating-a-net-core-rest-api-part-4-extras-fbd337aaf067">one last part</a> of this series where I give some links to other enhancements you can make to your API. That post gets into things like deployment, validation, and API documentation. This is it for the basic API however.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2caa77771be6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a .Net Core REST API — Part 2: Controller setup]]></title>
            <link>https://medium.com/@kieran.gillibrand/creating-a-net-core-rest-api-part-2-controller-setup-8f71408d8f4e?source=rss-c6bf91c383ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f71408d8f4e</guid>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[aspnetcore]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[net-core]]></category>
            <dc:creator><![CDATA[Kieran Gillibrand]]></dc:creator>
            <pubDate>Thu, 03 Jan 2019 11:06:52 GMT</pubDate>
            <atom:updated>2019-11-19T04:13:05.386Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating a .Net Core REST API — Part 2: Controller setup</h3><p>This is the 2nd part of a series of tutorials I’m putting together on creating a REST API with ASP.Net Core and Entity Framework Core. <a href="https://medium.com/@kieran.gillibrand/creating-a-net-core-rest-api-part-1-setup-and-database-modelling-47bccf8d5685">Last time</a> we got our project setup and generated models from our database. This time we’ll setup our database connection for the API itself, the API controller, and implement a handler for HTTP GET requests.</p><h3>Database Connection</h3><p>For our API to query our database we need to store our connection string somewhere and make our BlogContext available in the API controller.</p><p>There are a <a href="https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-strings#aspnet-core">few options</a> for storing connection strings in ASP.Net Core but we will be storing it in appsettings.json. Note that this file <strong>should never be in source control</strong> when it contains data like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*8hZ30O78G7hPm_5EsS_7ew.png" /><figcaption>Following the format in the link above will give us an appsettings.json looking something like this.</figcaption></figure><p>While our connection string for modelling is usually fairly simple you can configure <a href="https://www.npgsql.org/doc/connection-string-parameters.html">database specific parameters</a> in the API connection string. These parameters may affect security (SSL modes) or performance.</p><p>After adding our connection string we need to tell ASP.Net that we’re using Postgres and which connection string should be used. Note that name of the connection string should match your appsettings.json.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*JYJENGD55yNfOA6R_59opw.png" /><figcaption>We register the DataContext and its connection string in the ConfigureServices method of Startup.cs</figcaption></figure><p>After this we need to register our DataContext for <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.2">dependency injection</a> to our API controller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*38CfEYtD6FdIZiVYEkg9VQ.png" /><figcaption>AddScoped() registers our DataContext</figcaption></figure><h3>API Controller</h3><p>ValuesController is the default API controller that the project template generated for us. Currently it just returns some hardcoded values so we’ll make some adjustments.</p><ol><li>Firstly we should rename the controller class and source file. By convention the name of the controller (without the ‘Controller’ suffix) determines the endpoint of our API. I renamed it to PostsController as its operations are performed on blog posts.</li><li>Because we registered our DataContext as a service it will be injected through the Controller constructor. We just need to accept it as a parameter and store it.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*dty6hr8qYpIkbSnDWub6ow.png" /><figcaption>We add the single parameter constructor and store the provided DataContext.</figcaption></figure><h3>GET Handler</h3><p>Now we will implement a simple handler for HTTP GET requests to the Posts resource. We will start with GET as it’s a simple way of testing our database connection. Our GET handler will simply return the full representation of every post in the database, optionally filtering with an isPublic value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*RwWKTAPmn-0yZNZWH0vHbg.png" /></figure><p>Our handler is marked with the [HttpGet] which corresponds to its HTTP verb. It returns an ActionResult that contains some data. There are various provided implementations of ActionResult which correspond to HTTP status codes. HTTP 200 (OK) is represented by either OkResult (no content) or OkObjectResult (contains content). This convention is shared by the other results as well. If the result contains content then ASP.Net Core will automatically stringify it to JSON.</p><p>Our isPublic filter value is automatically parsed from the query string. Because query string parameters are generally optional it is a nullable bool which will be null if not provided. If you wish you can leave off the [FromQuery] attribute and the <a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-2.2#how-model-binding-works">model binding rules</a> will be followed to find the parameter.</p><p>If you’re not familiar with Entity Framework (Core or otherwise) it is generally queried using <a href="https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/getting-started-with-linq">LINQ</a>. Either with the query or method syntax. Behind the scenes EF Core and your database provider will generate an SQL query corresponding to queries against the DataContext collections (Posts, Comments, Users).</p><h3>Reference Loop Handling</h3><p>You may notice that our database schema and models have a potential for infinite loops in them. You can navigate from Post -&gt; Author -&gt; Posts -&gt; Author … As you can imagine this presents a problem for JSON.Net. In my experience my JSON response was malformed and cut in half.</p><p>To resolve this issue you can instruct JSON.Net to ignore the loops:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*TsLsiFZtHIEUgGfFWaru1Q.png" /><figcaption>Back in Startup.cs we can control various options of the JSON serialization</figcaption></figure><h3>Testing the API</h3><p>If you’ve added some data to your database manually then you can test the API with a tool like <a href="https://www.getpostman.com/">Postman</a>.</p><p>Because we’ve renamed the controller our endpoint will now be located at api/posts instead of api/values. Visual Studio will still launch your web browser pointing at api/values but you can change that in Solution Explorer -&gt; Properties -&gt; launchSettings.json.</p><h3>Next Time</h3><p>Next time we’ll implement other handlers for create, update, and delete (POST, PUT, DELETE).</p><p>The code for this example is available on <a href="https://github.com/kgillibrand/Database-First-ASP.Net-Core/releases/tag/2.0">Github</a>. <a href="https://medium.com/@kieran.gillibrand/creating-a-net-core-rest-api-part-3-finishing-our-controller-2caa77771be6">Up next</a> we’ll finish the other HTTP methods in our controller.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f71408d8f4e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a .Net Core REST API — Part 1: Setup and Database Modelling]]></title>
            <link>https://medium.com/@kieran.gillibrand/creating-a-net-core-rest-api-part-1-setup-and-database-modelling-47bccf8d5685?source=rss-c6bf91c383ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/47bccf8d5685</guid>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[aspnetcore]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[net-core]]></category>
            <dc:creator><![CDATA[Kieran Gillibrand]]></dc:creator>
            <pubDate>Wed, 02 Jan 2019 04:47:45 GMT</pubDate>
            <atom:updated>2019-11-19T04:14:04.905Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating a .Net Core REST API — Part 1: Setup and Database Modelling</h3><p>I’ll be putting together a series of tutorials on creating a REST API with ASP.Net Core and Entity Framework Core against a Postgres database. Microsoft has some <a href="https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-2.2&amp;tabs=visual-studio">great tutorials</a> as well but they weren’t always fully applicable to my use-case of developing an API against an existing database schema.</p><p>Anything in this tutorial should be possible on other platforms however I’ll be developing on Windows 10 with <a href="https://visualstudio.microsoft.com/vs/community/">Visual Studio Community 2017</a>.</p><h3>Project Setup</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*bOjBtS7rLPaT7pYI9MVZIg.png" /></figure><p>ASP.Net Core has a web application template that can help get us started. When creating your project be sure to select it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*tk2upK17WY6Rxr5ru-tNLQ.png" /></figure><p>After that select the plain API template.</p><p>You should end up with a simple API that returns some hardcoded values. The default configuration should run the API on IIS Express and launch a browser pointing to the API endpoint. You can also use a tool like <a href="https://www.getpostman.com/">Postman</a> to test the API. Just be aware that closing the browser window will stop the debugging session.</p><h3>Database Modelling</h3><p>Our API will run queries against our database using <a href="https://docs.microsoft.com/en-us/ef/core/">Entity Framework Core</a>. EF Core supports two models of development; <a href="https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db?tabs=visual-studio">Code First</a> and <a href="https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db">Database First</a>. Code first generates the database from models that you write manually. Database first is the opposite, generating the models from an existing database schema. We will be using database first in this case.</p><p>In order to model and query our Postgres database EF Core requires a <a href="https://docs.microsoft.com/en-us/ef/core/providers/">Database Provider </a>to be installed. We will install <a href="https://www.npgsql.org/">Npgsql</a> which is an open source Postgres provider. You can add it to your project from <a href="https://www.nuget.org/packages/Npgsql/">NuGet</a> using the Visual Studio GUI or the command line.</p><p>For the following steps you will need a Postgres database running. You can run one <a href="https://www.postgresql.org/download/windows/">locally on Windows</a> or on another server. I <a href="https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04">setup Postgres</a> on an Ubuntu server, created a database, and then <a href="https://blog.bigbinary.com/2016/01/23/configure-postgresql-to-allow-remote-connection.html">allowed external connections</a>. Once you have one running we can create a simple schema by running the following SQL script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/477b4b8538de8871bbd0914f428a7945/href">https://medium.com/media/477b4b8538de8871bbd0914f428a7945/href</a></iframe><p>You may notice I use plural table names in the database. If you want the model classes to have singular names you can install a <a href="https://www.nuget.org/packages/Bricelam.EntityFrameworkCore.Pluralizer">pluralizer package</a> to do this when the model is generated.</p><p>To model this schema we can run one of the following commands in command prompt, WSL, PowerShell, or the VS Package Manager Console. Make sure you are in the directory containing the project file (*.csproj).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0bb18e22b57c59f78f3aeead510361be/href">https://medium.com/media/0bb18e22b57c59f78f3aeead510361be/href</a></iframe><p>See the <a href="https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell#scaffold-dbcontext">command line reference</a> for more options.</p><p>Once the modelling is complete you will have 3 classes in the Models directory and one in the Context directory. The Models each represent a row in the database and it’s related data while the DataContext represents the full state of the database.</p><p>If you build the project you may notice a warning from a #warning directive in the OnConfiguring handler of BlogContext. EF Core embeds the connection string we used for modeling into the DataContext so that it will work for database access out of the box. This represents a potential security risk so you can remove the entire OnConfiguring handler and we will configure the connection string next time.</p><p>The source code for this tutorial is available on <a href="https://github.com/kgillibrand/Database-First-ASP.Net-Core/releases/tag/1.0">GitHub</a>. <a href="https://medium.com/@kieran.gillibrand/creating-a-net-core-rest-api-part-2-controller-setup-8f71408d8f4e">Up next</a> we’ll start setting up our API controller.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47bccf8d5685" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>