You are on page 1of 2

*The configuraytion applied Automattically without any line of code because you

inheret from class


-the LoyaltySetupDetailConfiguration class will be applied to the
LoyaltySetupDetail entity model during the migration process
-without explicitly calling "modelBuilder.ApplyConfiguration(new
LoyaltySetupDetailConfiguration())" in the OnModelCreating method.

*virtual keyword important in Navigation Prop, but not in Context.cs


-"public virtual DbSet<LoyaltySetupDetail> LoyaltySetupDetails { get; set; }"
in Context.cs (Generated Tables from Scafollding)
-In Entity Framework Core, the virtual keyword is used in the context of
virtual DbSet<T> to enable certain features related to change tracking and lazy
loading.

-"public virtual ICollection<LoyaltySetupDetail> LoyaltySetupDetails { get;


set; }" (Navigation Prop)
-In this case, the virtual keyword allows for the possibility of lazy
loading,
meaning that related entities are loaded from the database only when you
access the navigation property. Without virtual, lazy loading won't be supported
for that property.

*The steps to deal with SP in SQL Server

1-Create SP in SQL Server Query

2- Create a model Dto to match the result of SP

3-Create a table in Context class to call it with _context :


"public DbSet<RetailCustomerLoyaltyPointsSPDto>
RetailCustomerLoyaltyPointsSPDtos { get; set; }"

-in onModelCreatingMEthod : to deal with this model ot table need to difine it


has no key to can deal with this table
modelBuilder.Entity<RetailCustomerLoyaltyPointsSPDto>(e =>
{
e.HasNoKey();
e.ToView(null); // or Replace with the actual stored procedure name
});

4- in Controoler : var Paramter = new SqlParameter("NameSring", Value);


// var result = dbContext."YourDTOClass".FromSqlRaw(@"EXEC
MyStoredProcudureName",paramter).ToList();

[HttpGet("PointsDtos")]
public async Task<ActionResult<RetailCustomers>>
GetCustomerPointsFromDtos(string phone)
{
try
{
var Paramter = new SqlParameter("Phone", phone);
var resurt = await Task.Run(() =>
_context.CustomerPointsReadSPDtos.FromSqlRaw(@"Exec GetRetailCustomerLoyaltyPoints
@Phone", Paramter).ToListAsync());
if (resurt == null)
{
return BadRequest();
}
return Ok(resurt

You might also like