Posts

CQRS and MediatR

Image
   In this article, we are going to discuss the working of CQRS and MediatR patterns and step-by-step implementation using .NET Core 6 Web API. Agenda Introduction of CQRS Pattern When to use CQRS MediatR Introduction of CQRS Pattern CQRS stands for Command and Query Responsibility Segregation and uses to separate read(queries) and write(commands). In that, queries perform read operation, and command perform writes operation like create, update, delete, and return data. As we know, in our application we mostly use a single data model to read and write data, which will work fine and perform CRUD operations easily. But, when the application becomes a vast in that case, our queries return different types of data as an object so that become hard to manage with different DTO objects. Also, the same model is used to perform a write operation. As a result, the model becomes complex. Also, when we use the same model for both reads and write operations the security is also hard to manage when t

Replace cursor with while loop in sql.

Declare @count int; set @count =1; Declare @loop int; declare @tempItem_Id bigint; select @loop = COUNT(item_id_big) from tbl_item_master; while @count <= @loop begin  WITH MyCte AS (     select   item_id_big,              RowNum = row_number() OVER ( order by item_id_big )     from     tbl_item_master )  select @tempItem_Id = item_id_big from MyCte where RowNum = @count;  print convert(varchar(15), @tempItem_Id)+ ' '+ convert(varchar(4),@count)  + ' \n ';  set @count = @count+1; end

How to get div whose id start with “panel” from page body using jquery

Query : How to get div whose id start with “panel” from page body using jquery. solution : $('div[id^="panel_"]') the above jquery script will return you list of div whose id start with “panel”.

EntityFramework inner join

Image
Column concatenation using Linq to EntityFramework. here we have one simple example where there are two tables. one Employee with following fileds CREATE TABLE [dbo].[empMaster]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Age] [int] NULL, [IsActive] [bit] NULL CONSTRAINT [DF_empMaster_IsActive]  DEFAULT ((1)), [CreatedDate] [datetime] NULL CONSTRAINT [DF_empMaster_CreatedDate]  DEFAULT (getdate()),  CONSTRAINT [PK_empMaster] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] and another table is with CREATE TABLE [dbo].[employee]( [id] [int] IDENTITY(1,1) NOT NULL, [Salary] [int] NULL,  CONSTRAINT [PK_employee] PRIMARY KEY CLUSTERED ( [id] ASC )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] Now i want to get name of employee and salary of that employee. so i used innerjoin like this select em.id,em

Prepare DTO layer by using below script

DECLARE @CurID INT, @MaxID INT Declare @sql nvarchar(MAX) Declare @TmpTable table (ID int Identity(1,1), c_Column_name varchar(500),c_Data_type varchar(50),c_character_Maximum_length nvarchar(50)) Insert into @TmpTable (c_Column_name,c_Data_type,c_character_Maximum_length)     SELECT COLUMN_NAME ,DATA_TYPE ,CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TT_M_User'  --Table Name ORDER BY ORDINAL_POSITION ASC; set @CurID = 1 set @sql='' SELECT @MaxID=Max(ID) FROM @TmpTable WHILE @MaxID >=@CurID BEGIN -- Logic to be performed select @sql = @sql + char(13)+ ' public ' +     case c_Data_type     when 'varchar' then ' string '     when 'nvarchar' then ' string '     when 'bit' then ' bool '     when 'datetime' then ' DateTime '     when 'binary' then ' Byte[] '     else c_Data_type end + ' ' + c_Column_Name + ' {get;set;} 

ASP.NET : Difference between Server.Transfer and response.Redirect

Response.Redirect sends message to the browser saying it to move to some different page, while server.transfer does not send any message to the browser but rather redirects the user directly from the server itself. So in server.transfer there is no round trip while response.redirect has a round trip and hence puts a load on server. Using Server.Transfer you can not redirect to a different from the server itself. Example if your server is www.yahoo.com you can use server.transfer to move to www.microsoft.com but yes you can move to www.yahoo.com/travels, i.e. within websites. This cross server redirect is possible only using Response.redirect. With server.transfer you can preserve your information. It has a parameter called as “preserveForm”. So the existing query string etc. will be able in the calling page. Use server.transfer to navigate within website. And use Response.redirect to redirect to another website. You can transfer current users page request to another page with

DBCC CHECKIDENT

Question Which command is used reseed the identity value? Answer DBCC CHECKIDENT can be used to manually set a new current identity value for the identity column. DBCC CHECKIDENT ("Sales.ProductType", RESEED, 10);