Q21. What is the difference between Include and Join in entity framework?
Q22. What is the strategy to migrate from .net framework to .net core?
Q23. What are the 3 parts of JWT?
Q24. How JWT works? How we get values of JWT token?
Q25. What will be your approach in case you want to call a manual stored procedure from your dot net code with Entity Framework?
------------------------------------------------------------------------------------------------------------------------------------------
Q21. What is the difference between Include and Join in entity framework?
Answer:
At times we get same results on using Include or Join but below are the differences.
Include
1. It does the eager loading of underlying property for you.
2. No filter on columns.
3. Include can only be used with actual inter related tables. They must have primary-foreign key relation between them. eg Product and Product details table.
4. In example below it generates the left join between table product and productdetails behind the scenes.
var products = context.Products
.Include(p => p.ProductDetails)
.ToList();
------------
Join
1. It does not do the eager loading.
2. We can put filter on number of columns and columns we want. The advantage of Join is, if you dont need additional data you wont get it.
3. Joins are flexible enough to query around tables which are not directly related like student and Collage over city to check all collages present in student city.
4. For above product and productDetails below will be the query. Join gives more flexibility but bigger code.
var productsWithDetails = from product in context.Products
join details in context.ProductDetails
on product.Id equals details.ProductId
select new
{
Product = product,
ProductDetails = details
};
var result = productsWithDetails.ToList();
------------------------------------------------------------------------------------------------------------------------------------------
Q22. What is the strategy to migrate from .net framework to .net core?
Answer:
At times we have to migrate our old application from .net framework to .net core for containerization, plateform independent etc.
Below are the points we have to take care while migrating.
So migration will happen in 3 phases.
1. Data/Model layer: Migrate the Entity framework to EF core. One way is to upgrade the asp.net EF to EF 6 which is much similar to EF core.
2. Business/ Controller layer: .net classes to .net core classes.
3. UI layer: Asp.net page to Asp.net core pages.
------------------------------------------------------------------------------------------------------------------------------------------
Q23. What are the 3 parts of JWT?
Answer:
JWT - Json Web Token.
JWT token consists of 3 parts separated by . dots
1. Header
2. Payload.
3. Signature
Header - contains two part type and algo.
{
"alg": "HS256",
"typ": "JWT"
}
Payload: Usually contains the information about the user like role, name, status etc. These are called claims ie in payload we have claims details like role, name, status etc
{
"sub": "1234567890",
"name": "John Doe",
"admin": true
}
Signature: To create the signature part you have to take the encoded header, the encoded payload, a secret, the algorithm specified in the header, and sign that.
HMACSHA256(
base64UrlEncode(header) + "." +
base64UrlEncode(payload),
secret)
------------------------------------------------------------------------------------------------------------------------------------------
Q24. How JWT works? How we get values of JWT token?
Answer:
In authentication, when the user successfully logs in using their credentials, a JSON Web Token will be returned.
Whenever the user wants to access a protected route, it should send the JWT, typically in the Authorization header using the Bearer schema. Therefore the content of the header should look like the following.
Authorization: Bearer <token>
------------------------------------------------------------------------------------------------------------------------------------------
Q25. What will be your approach in case you want to call a manual stored procedure from your dot net code with Entity Framework?
Answer:
1) If the stored procedure is doing an update/insert/delete (not returning entities), I’d use Database.ExecuteSqlCommand in EF6 or Database.ExecuteSqlRaw in EF Core.
2) If the stored procedure returns rows that map to an entity, I’d use SqlQuery in EF6 or FromSqlRaw in EF Core.