question

MichaelPenney-8341 avatar image
0 Votes"
MichaelPenney-8341 asked azure-cxp-api edited

ASP.NET core - can I use an sql view instead of a table in my app?

Hi,

I was just wondering if anyone could offer a bit of help. I'm currently a work term student and I've been asked to create a view in SQL server and use that for the application we are developing. Creating a view is easy enough but I'm not sure on how to use the view inside of the application. I'm building the app with asp.net core. Any help would be appreciated!

Thanks,
Mike P.

azure-webapps
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Don't forget to accept an answer to help future visitors :)

0 Votes 0 ·

Sorry I was using my work laptop and it won't let me accept and answer or sign in! Thanks everyone for the help you saved me a lot of grief on my project!!

0 Votes 0 ·
markxa avatar image
1 Vote"
markxa answered markxa edited

Assuming you're using Entity Framework Core, make sure you're using EF Core 3 and then it will scaffold views for you as keyless entity types (previously known as query types)- see https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/#reverse-engineering-of-database-views. If you're tied to a previous version, you can still do it with query types in 2.1 as long as you scaffold it yourself in OnModelCreating, or whatever version you're on you can always fall back to a raw SQL SELECT statement.

At a lower level, if you're not using EF then for most purposes you can treat views as read-only tables.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ManojSharma-1740 avatar image
0 Votes"
ManojSharma-1740 answered

Hi Mike,

If you are use Views in the same manner as you would use a SQL Server database table object.

So, you can either use a stored procedure to query the view and than invoke Stored procedure using ADO.NET from your ASP.NET Core application or you can also use a select query with ADO.NET against you view.

You can refer to sample code of using ADO.NET here (https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ado-net-code-examples)

-Thanks,
Manoj

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

C-9462 avatar image
0 Votes"
C-9462 answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
0 Votes"
DSPatrick answered

Asp.net core is not currently supported here on QnA. I'd try asking for help in dedicated forums here.


https://forums.asp.net/1255.aspx/1?ASP+NET+Core


https://stackoverflow.com/questions/tagged/asp.net-core


--please don't forget to Accept as answer if the reply is helpful--


Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management


Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.







5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.