Monday 2 September 2024

Migration comments in .net 8 or .net core

1. Install latest Ef core, Design and related packages

2. Update db connection config in Web/Api/Azure funtion APP and set as startup project.

3. Once Code first Entities Created in library project then Open package manger console => Select corresponding library project.

4. Add Migration

PM> Add-Migration migration_name_description

Build started...

Build succeeded.

5. To undo this action, use Remove Migration

PM> Remove-Migration migration_name_description

6. Update Database

PM> update-database –verbose

Build started...

Build succeeded.

It will generate DML & DDL scripts. 

Friday 16 August 2024

.net Package upgrade with bindings

 The solution to this is actually quite simple and elegant.

  1. Remove all your binding redirects in Web.config / app.config;
  2. Go to Package Manager Console;
  3. Enter the command Add-BindingRedirect (you can also specify a target project using -ProjectName "SpecificProject");
  4. All necessary binding redirects are generated;
  5. Run your application and see if it works properly. If not, add any missing binding redirects that the command missed.

 

From < https://stackoverflow.com/questions/50036791/find-unused-unnecessary-assemblybinding-redirects>

Thursday 2 May 2024

Difference between IEnumerable,IQueryable VS List

 First the difference between List<T>, IEnumerable<T> and IQueryable<T>.

 The content of List<T> will always be loaded into memory, because it uses an array in the background.


The content of IEnumerable<T> will only load the requested item into the memory. Compiler sets up a state machine during compiling a method with IEnumerable<T> that has a yield return T. So only one item at a time will be loaded into memory in this case.


IQueryable<T> is "special" version of IEnumerable<T>. Specifically designed to query data sources, and implemented by data providers. Like EF, NHibernate. So when you tell EF to fetch the data with .ToListAsync<T>() EF will only then go the database and execute the generated query. See the docs for more info about IQueryable<T>.