E
engahmedbarbary
Guest
problem
How to write function done by entity framework by ado.net ?
I work on SQL server 2012 with csharp app with entity framework .
I need to rewrite function below by ado.net
so that how to make that ?
database blow :
CREATE TABLE [dbo].[User](
[Id] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [nvarchar](250) NULL,
[LastName] [nvarchar](250) NULL,
[nvarchar](250) NULL,
[Phone] [nvarchar](50) NULL,
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, _
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[UserMarks] Script Date: 8/15/2018 9:22:00 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserMarks](
[id] [int] NOT NULL,
[userId] [int] NULL,
[mark] [decimal](18, 2) NULL,
CONSTRAINT [PK_UserMarks] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, _
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
What I have tried:
public async Task<List<vmMarks>> GetResult()
{
List<vmMarks> query = null;
try
{
using (_ctx)
{
query = await (from um in _ctx.UserMarks
join m in _ctx.User on um.UserId equals m.Id
select new vmMarks
{
mid = (int)m.Id,
mName = m.FirstName + " " + m.LastName,
mMark = (decimal)um.Mark
}).OrderByDescending(x => x.mMark).ToListAsync();
}
}
catch (Exception ex)
{
ex.ToString();
}
return query;
}
[url="https://social.msdn.microsoft.com/Forums/en-US/92d9be22-3a78-4890-a993-10e00dd2cc5d/how-to-rewrite-function-make-by-entity-framework-by-adonet-?forum=csharpgeneral"]Continue reading...[/url]
How to write function done by entity framework by ado.net ?
I work on SQL server 2012 with csharp app with entity framework .
I need to rewrite function below by ado.net
so that how to make that ?
database blow :
CREATE TABLE [dbo].[User](
[Id] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [nvarchar](250) NULL,
[LastName] [nvarchar](250) NULL,
[nvarchar](250) NULL,
[Phone] [nvarchar](50) NULL,
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, _
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[UserMarks] Script Date: 8/15/2018 9:22:00 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserMarks](
[id] [int] NOT NULL,
[userId] [int] NULL,
[mark] [decimal](18, 2) NULL,
CONSTRAINT [PK_UserMarks] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, _
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
What I have tried:
public async Task<List<vmMarks>> GetResult()
{
List<vmMarks> query = null;
try
{
using (_ctx)
{
query = await (from um in _ctx.UserMarks
join m in _ctx.User on um.UserId equals m.Id
select new vmMarks
{
mid = (int)m.Id,
mName = m.FirstName + " " + m.LastName,
mMark = (decimal)um.Mark
}).OrderByDescending(x => x.mMark).ToListAsync();
}
}
catch (Exception ex)
{
ex.ToString();
}
return query;
}
[url="https://social.msdn.microsoft.com/Forums/en-US/92d9be22-3a78-4890-a993-10e00dd2cc5d/how-to-rewrite-function-make-by-entity-framework-by-adonet-?forum=csharpgeneral"]Continue reading...[/url]