.net Core 2.1 and SQL via EF Core 2.1 -The revisit

It’s time to revisit this topic but for the latest up dates for .Net Core (v 2.1.1) and EF Core (v 2.1)

Let’s start with the common project using, in my case, VS 2017 15.7.4.  Start a .Net Project based on v 2.1.x (I currently have installed .Net Core SDK v 2.1.301
  (Gee think we have enough versions of things  😯 )

I’m doing a .Net Core Class so I can get my DBContext and Table models in place….
We start with some Packages:

Microsoft.EntityFrameworkCore.SqlServer (2.1.1)
Microsoft.EntityFrameworkCore.SqlServer.Design (1.1.5)
Microsoft.EntityFrameworkCore.Tools (2.1.1)

Next, time for a database and let’s Scaffold a DB Context and our models… On the .Net Core project start up the Package Manager Console.

dotnet ef dbcontext scaffold 
  "Server={ServerName};DataBase={DataBaseName};Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
   Microsoft.EntityFrameworkCore.SqlServer
   --output-dir Models
   --table {table1Name} --table {table1Name} --table {table1Name} .....
For Connection Strings to SQL with a user/pass, an example would be
"Server={ServerName;DataBase={DataBaseName}g;Integrated Security=False; User ID={sql user};Password={sql user Pass};
Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;
ApplicationIntent=ReadWrite;MultiSubnetFailover=False"

 

The Walk-Through…

Line 1 – dotnet ef dbcontext scaffold This is the start of the command. As we see dotnet is the actual start of the SDK utility. It is worth looking this up. “ef dbcontext scaffold” is how we start  the EF scaffold.
Line 2 – The Connection String **1
“Server={ServerName};DataBase={DataBaseName};Integrated Security=True;Connect   Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False”
Line 3 – This is the provider used for MS SQL server. Yes it would be different if another database was being used.
Line 4 – The –output param is giving us a way to make sure we put all models/dbcontext in a folder in the project.
Line 5 – The –table allows one to generate models (and DbContext) for only certain tables in the DB.
 

**1    This is the standard SQL connection string. This will take on various forms depending on what you are connecting to. And yes, one can use the localdb.

 

 

 

 

 

Dotnet Core Templates, or DOTNET new -i “the magic”

Time to touch on this topic again… because every time a new DOTNET SDK comes out I seem to lose the new templates. I understand the why, and ya I wish the .Net Core group would fix it. 

The “why”- each time one updates to a new Core SDK, the template scaffolds get placed into a new folder (usually under your users directory in a annoying place like ….\.templateengine\dotnetcli\”version of sdk”\). So each time you move to a new DOTNET SDK, this becomes a problem.

The second part of of DOTNET new -i that is an issue, is if you have different nuget repositories set in VS. It’s a great feature in VS 2017 where one can add additional package management sources… problem is with the DOTNET command line when you want to bring in new templates.

So, why am I going on about this? Well as I move from SDK version to version… I would like the damn templates I’ve added to either get updated (the standard ones do), or at least make sure they are available to the new SDK….  How hard can it be….

So here’s the list of what I keep installing from (dotnet Templates on github)

Here’s my list:

dotnet new -i “Microsoft.AspNetCore.SpaTemplates::*”    – this one always

dotnet new -i “Boxed.Templates::*”  – I’m still undesided about boxed.

dotnet new -i Microsoft.AspNetCore.Blazor.Templates::*  – nice little framework that has become a 1st class citizen in VS. Make sure you also check out the VS extension.

dotnet new -i “RaspberryPi.Template::*” – who does not like Iot stuff. Also available in VS as a 1st class citizen.

Setting up SSL Certs for IIS 10

So as I enter the world of suffering to get SSL working on some sites… I noticed that most SSL providers (at least the free one I’ve been using) – don’t provide the cert in the file format I need to do just a “import” within IIS. Go figure!

So what to do?

Well as it turns out there’s a utility to make the the crt formatted file into a pfx (which is what IIS likes).

openssl  – look for it on the inter-tubes 

openssl pkcs12 -export -out anotherCert.pfx -inkey private.key -in certificate.crt

Another point… I generally use SSL For Free for creating quick free SSL certs- they only last 90 days, but if you want longer lasting Certs… yeap you have to pay for them.

 And finally, hosting multiple sites on a single IP and IIS server, one does need to get specific site SSL certs. The thing to remember to so make sure you select the “Require Server Name” check box as on, in the Bindings config. Otherwise you will get an error when selecting a site SSL cert. The warning message will say something to the effect of the cert being set for all sites being hosted. Ya that’s not what you want of course, as a cert for Site.Name.Domain will get assigned to all the sites being hosted. It’s a simple check box to miss, but it’s important.  

BizTalk: The almost lost secret sauce

As I was poking about trying to move a support utility forward- I noticed that one command in me “grunt” works console app made use of a Stored Procedure I buried in the BizTalk MSG DB. It’s not big thing. Until I realized that when our systems where upgraded and moved about, I didn’t move my magic SP forward… Well Duh! (I won’t go into how one should never really bolt on crap to a server product, but it was a useful tool)…

The SP was just complicated enough not to be able to just re-create from scratch – Yeah, one of those.

In a nutshell, the SP looks through active ports within a BizTalk system and does an active message count for each port that is processing a message (like I said- Not a trivial matter. Lucky, or was I foreseeing the future? I placed the SP code inside my console app- so as not to lose it….. Wow, I must be a “genus”.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Scott Edwards
-- Create date: way back
-- Description: Used by the integration tool to get port message counts.
-- =============================================
CREATE PROCEDURE MHK_PortMSGcounts
AS
BEGIN
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
SET DEADLOCK_PRIORITY LOW

CREATE TABLE #Temp (MaxRetries int, Active int, SendPort nvarchar(256), IsPrimaryTransport int)
declare @nvcAppName sysname

declare MyCursor CURSOR FAST_FORWARD FOR
SELECT nvcApplicationName FROM [BizTalkMsgboxDb]..[Applications] WITH (NOLOCK)

open MyCursor
FETCH NEXT FROM MyCursor INTO @nvcAppName
WHILE (@@FETCH_STATUS = 0)
BEGIN
INSERT INTO #Temp
exec (' SELECT MAX(q.nRetryCount) AS MaxRetries
,COUNT(*) AS Active<br>
,sp.nvcName AS SendHandlersHostServiceName
,spt.bIsPrimary AS IsPrimaryTransport
FROM ' + @nvcAppName + 'Q as q WITH (NOLOCK)
INNER LOOP JOIN Subscription as s WITH (NOLOCK) ON q.uidServiceID = s.uidServiceID AND s.uidPortID = q.uidPortID
INNER LOOP JOIN [BizTalkMgmtDb]..[bts_sendport] as sp WITH (NOLOCK) ON q.uidServiceID = sp.uidGUID
INNER LOOP JOIN [BizTalkMgmtDb]..[bts_sendport_transport] as spt WITH (NOLOCK) ON sp.nID = spt.nSendPortID AND spt.uidGUID = q.uidPortID
GROUP BY sp.nvcName, s.uidPortID, spt.bIsPrimary
ORDER BY SendHandlersHostServiceName ASC')
FETCH NEXT FROM MyCursor INTO @nvcAppName
END
SELECT * FROM #Temp ORDER BY Active DESC
close MyCursor
deallocate MyCursor
DROP TABLE #Temp
END
GO

 

Windows Community Toolkit Major update

In the “… case you didn’t hear department…”, looks like UWP Toolkit or are we just now calling it Windows Community Toolkit got a major revision…

Check it out:

WindowsCommunityToolkit – The Windows Community Toolkit is a collection of helper functions, custom controls, and app services. It simplifies and demonstrates common developer tasks building UWP ap…

 

And… on Docs:

The Windows Community Toolkit is a collection of helper functions, custom controls, and app services. It simplifies and demonstrates common developer tasks building UWP apps for Windows 10.

 

Site Update

I’ve noticed an increase of comments to my site- Now I’m not opposed to anyone putting comments here (If I did, I would of course turn comments off). But really folks- if you post from IP’s that are on Blocked-lists, or put odd statements in a comment, then why would I allowed them through?

So, you will notice the annoying Capcha- not perfect… but there are also spam controllers collecting you as well. 😉 

My point is- Stop “bot-ing” my site (ya I know that’s never going to stop)… if you are real person and your comment does not show up… well it happens. I’ve too many hits on my firewall from Ad trolls, not everything is going to make it through.

~SG

Build 2018 Session: Entity Framework Core 2.1: Simple, Powerful Data Access for .NET

Entity Framework Core 2.1: Simple, Powerful Data Access for .NET

Entity Framework Core 2.1: Simple, Powerful Data Access for .NET : Build 2018

We know the data tier is one of the most important parts of your application. That’s why we’ve worked hard on the latest release of Entity Framework Core 2.1…

Source: On YouTube

Build 2018: Session: Windows 10 Your Phone, Sets, Timeline iOS, Android

Windows 10 Your Phone, Sets, Timeline iOS, Android

Microsoft Build 2018: Windows 10 Your Phone, Sets, Timeline iOS, Android

Microsoft’s Joe Belfiore shows new features coming to Windows 10 at Build 2018, including Your Phone app, Timeline for iOS with Microsoft Edge and Timeline f…

Source: On YouTube