I work on Blazor application server side. I design web API to interact with razor pages.
My issue is which is suitable for my scenario? Using ADO.NET or Entity Framework Core?
What I try is as below:
So is using data reader ADO.NET better or using Entity Framework Core?
Some developers tell me why use ADO.NET. It is old technology and this is not good because it opens and closes connection with every load page and entity framework does not do that.
Also, is ADO.NET easy for hacking from Entity Framework Core?
Is this correct?
Is that better or using Entity Framework Core?
I depend on code first technology.
Result of the statement above is 10000 rows as maximum.
What I have tried:
[HttpGet]
[Route("GetAllServersDetails")]
public IActionResult GetAllServersDetails()
{
string query = "";
query = "select s.ServerID, s.Server_Name as ServerName,isnull(s.ServerIp,'') as ServerIp,s.ServerTypeId,isnull(st.ServerType,'') as ServerType,s.OsTypeId,isnull(os.DetailsName,'') as OsType,s.HostedZoneId,isnull(hostedzone.DetailsName,'') as HostedZone,s.ServerityId,isnull(serverity.DetailsName,'') as Serverity,s.HostedTypeId,isnull(hostedType.DetailsName,'') as HostedType,isnull(s.ServerRoleId,0) as ServerRoleId,isnull(serverrole.DetailsName,'') as ServerRole,isnull(s.DRRequired,0) as DRRequiredID,isnull(drrequired.DetailsName,'') as DRRequired,isnull(s.Remarks,'') as Remarks,isnull(s.OwnerFileNo,'') as ownerfilenumber, s.IsActive from [dbo].[ServerNames] s with(nolock)
inner join [dbo].[ServerTypes] st with(nolock) on st.ServerTypeId=s.ServerTypeId
left join Details os with(nolock) on os.ID=s.OsTypeId and os.HeaderId=12
left join Details hostedzone with(nolock) on hostedzone.ID=s.HostedZoneId and hostedzone.HeaderId=13
left join Details serverity with(nolock) on serverity.ID=s.ServerityId and serverity.HeaderId=14
left join Details hostedType with(nolock) on hostedType.ID=s.HostedTypeId and hostedType.HeaderId=15
left join Details serverrole with(nolock) on serverrole.ID=s.ServerRoleId and serverrole.HeaderId=16
left join Details drrequired with(nolock) on drrequired.ID=s.DRRequired and drrequired.HeaderId=17";
try
{
ICollection<object> ApplicationsDataValues =
new List<object>();
using (var command =
_context.Database.GetDbConnection().CreateCommand())
{
command.CommandText = query;
command.CommandType = CommandType.Text;
_context.Database.OpenConnection();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
ApplicationsDataValues.Add(new
{
ServerID = reader.GetFieldValue<Int32>(0),
ServerName =
reader.GetFieldValue<string>(1).ToString(),
ServerIp = reader.GetFieldValue
<string>(2).ToString(),
ServerTypeId =
reader.GetFieldValue<Int32>(3),
ServerType = reader.GetFieldValue
<string>(4).ToString(),
OsTypeId = reader.GetFieldValue
<Int32>(5),
OsType = reader.GetFieldValue
<string>(6).ToString(),
HostedZoneId =
reader.GetFieldValue<Int32>(7),
HostedZone =
reader.GetFieldValue<string>(8).ToString(),
ServerityId = reader.GetFieldValue<Int32>(9),
Serverity = reader.GetFieldValue<string>(10).ToString(),
HostedTypeId = reader.GetFieldValue<Int32>(11),
HostedType = reader.GetFieldValue<string>(12).ToString(),
ServerRoleId = reader.GetFieldValue<Int32>(13),
ServerRole = reader.GetFieldValue<string>(14).ToString(),
DRRequiredID = reader.GetFieldValue<string>(15).ToString(),
DRRequired = reader.GetFieldValue<string>(16).ToString(),
Remarks = reader.GetFieldValue<string>(17).ToString(),
ownerfilenumber = reader.GetFieldValue<string>(18).ToString(),
IsActive = reader.GetFieldValue<bool>(19)
});
}
}
}
return StatusCode
(200, ApplicationsDataValues);
}
catch (Exception e)
{
return StatusCode(500, e);
}
}