This blog contains Azure, .Net, SQL & Full stack development concepts and code fixes.
Sunday, 26 January 2025
Apply Migration and DB schema if not exist while run local
Monday, 13 January 2025
EF Core 9 Generate Code First from Existing DB
1.Install EF Core, EF core Design, EF sql server using nuget packages.
2. Open package manger console
3. Select the project where need to place entity and DbContext
4.Run below comments with modified inputs which is highlighted.
dotnet ef dbcontext scaffold "Server={Server};Database={DBname};User Id={db user name};Password={PWD};Encrypt=True;TrustServerCertificate=True;" Microsoft.EntityFrameworkCore.SqlServer --output-dir DbEntity --context-dir DbContext --context CoreDbContext --use-database-names --force --project D:/Source_vs2022/Core.Data/Core.Data.csproj
5. Now we can see Db context and db entity
6.Migrate to Full Code-First
If you want to start using migrations with the generated context execute below in same package mager console.
- Add migrations:
dotnet ef migrations add InitialCreate --project Core.Data
- Update the database:
dotnet ef database update --project Core.Data --verbose
- InitialCreate is migration name
- Core.Data is project name which contains EF.
- In case any other error occurs like missing OnConfigure then add below code in DBContext file.
- after migration generated remove it below code due to security reason.
Sunday, 12 January 2025
Azure Cloud Services
Services are offered over the public internet and available to anyone who wants to purchase them. Cloud resources, such as servers and storage, are owned and operated by a third-party cloud service provider, and delivered over the internet.
Private cloudA private cloud consists of computing resources used exclusively by users from one business or organization. A private cloud can be physically located at your organization's on-site (on-premises) datacenter, or it can be hosted by a third-party service provider.
Hybrid cloudA hybrid cloud is a computing environment that combines a public cloud and a private cloud by allowing data and applications to be shared between them.
Public cloud | Private cloud | Hybrid cloud |
---|---|---|
No capital expenditures to scale up. Applications can be quickly provisioned and deprovisioned. Organizations pay only for what they use. | Hardware must be purchased for start-up and maintenance. Organizations have complete control over resources and security. Organizations are responsible for hardware maintenance and updates. | Provides the most flexibility. Organizations determine where to run their applications. Organizations control security, compliance, or legal requirements. |
This cloud service model is the closest to managing physical servers; a cloud provider will keep the hardware up-to-date, but operating system maintenance and network configuration is up to you as the cloud tenant. For example, Azure virtual machines are fully operational virtual compute devices running in Microsoft datacenters. An advantage of this cloud service model is rapid deployment of new compute devices. Setting up a new virtual machine is considerably faster than procuring, installing, and configuring a physical server. The most flexible cloud service. You configure and manage the hardware for your application.
PaaS: Platform-as-a-ServiceThis cloud service model is a managed hosting environment. The cloud provider manages the virtual machines and networking resources, and the cloud tenant deploys their applications into the managed hosting environment. For example, Azure App Services provides a managed hosting environment where developers can upload their web applications, without having to worry about the physical hardware and software requirements. Focus on application development. Platform management is handled by the cloud provider.
SaaS: Software-as-a-ServiceIn this cloud service model, the cloud provider manages all aspects of the application environment, such as virtual machines, networking resources, data storage, and applications. The cloud tenant only needs to provide their data to the application managed by the cloud provider. For example, Microsoft Office 365 provides a fully working version of Microsoft Office that runs in the cloud. All you need to do is create your content, and Office 365 takes care of everything else. Pay-as-you-go pricing model. Users pay for the software they use on a subscription model.
Cloud service model comparisonThursday, 2 January 2025
Each table wise total records in sql
To retrieve the total number of records (rows) for each table in a SQL Server database, you can use the sys.tables
and sys.dm_db_partition_stats
views. Here's a query to accomplish this:
Query to Get Row Counts for All Tables
SELECT
t.name AS TableName,
SUM(p.rows) AS TotalRecords
FROM
sys.tables t
INNER JOIN
sys.partitions p ON t.object_id = p.object_id
WHERE
p.index_id IN (0, 1) -- 0 = Heap, 1 = Clustered index
GROUP BY
t.name
ORDER BY
TotalRecords DESC;
Explanation of Query:
sys.tables
: Contains information about all tables in the database.sys.partitions
: Provides information about partitions of tables and indexes. Therows
column contains the number of rows for each partition.index_id IN (0, 1)
: Ensures you count rows only for heap (no clustered index) or clustered index partitions.
Sample Output:
TableName | TotalRecords |
---|---|
Customers | 1200 |
Orders | 450 |
Products | 150 |
Wednesday, 1 January 2025
Types of publish dotnet core
Publish the app as a framework-dependent deployment
dotnet publish -c Release -o publish-fd
In the preceding command:
-c Release
specifies that the app should be built in release mode. This optimizes the app for performance.-o
specifies the name of the output directory. In this case, the output directory will be named publish-fd.
This command publishes the app as a framework-dependent deployment to the publish-fd directory.
Publish for self-contained deployment
publish the app as a self-contained deployment for 64-bit Windows:
dotnet publish -c Release -r win-x64 -o publish-scd-win64 --self-contained
In the previous command:
-c Release
specifies that the app should be built in release mode. This optimizes the app for performance.-r win-x64
specifies that the app should be published for 64-bit Windows.win-x64
is the runtime identifier (RID) for 64-bit Windows, so the app is published as a self-contained deployment for 64-bit Windows.-o publish-scd-win64
specifies the output directory for the published app.--self-contained
specifies that the app should be published as a self-contained deployment.
publish the app as a self-contained deployment for 64-bit Linux:
dotnet publish -c Release -r linux-x64 -o publish-scd-linux64 --self-contained
This time, the -r linux-x64
option specifies that the app should be published for 64-bit Linux.