If you are talking about updating Umbraco data programmatically, eg as part of an import, or in a custom package, then you can use the Umbraco Services gateway to access the ContentService and MediaService which enable you to query, and update data directly in the database - but this is slow, and shouldn't be used on the frontend.
Finally if you have a custom database table, that you need to query, perhaps a table of products not managed by Umbraco that you need to query data from, then you can connect directly to the Umbraco database, and use SQL.
Umbraco ships with a lightweight ORM called NPoco, which means you can create a c# class that represents your database table, and write SQL to pull back data,
There is some info here about Creating a custom database table:
Thank you Marc...Actually my requirement is to show the name of the logged in user instead of email in the website. I am using active directory authentication for members. I tried adding identity to the context but its getting overwritten.
Database Query
How can I query the umbraco database to get data?
Hi Vijitha
Normally you wouldn't! As accessing the database is slow.
Umbraco has a published cache, and usually you query and display content from the Cache:
The 'UmbracoHelper' is a good starting point to query your published data:
https://our.umbraco.com/Documentation/Reference/Querying/UmbracoHelper/
If you are talking about updating Umbraco data programmatically, eg as part of an import, or in a custom package, then you can use the Umbraco Services gateway to access the ContentService and MediaService which enable you to query, and update data directly in the database - but this is slow, and shouldn't be used on the frontend.
https://our.umbraco.com/Documentation/Reference/Management/Services/ContentService/
Finally if you have a custom database table, that you need to query, perhaps a table of products not managed by Umbraco that you need to query data from, then you can connect directly to the Umbraco database, and use SQL.
Umbraco ships with a lightweight ORM called NPoco, which means you can create a c# class that represents your database table, and write SQL to pull back data,
There is some info here about Creating a custom database table:
https://our.umbraco.com/documentation/extending/database/ (also some examples here of using NPoco in V8 that will be similar: https://codeshare.co.uk/blog/how-to-do-crud-operations-with-npoco-in-umbraco-8/)
regards
marc
Thank you Marc...Actually my requirement is to show the name of the logged in user instead of email in the website. I am using active directory authentication for members. I tried adding identity to the context but its getting overwritten.
Hi Vijitha Ahh I see!! In which case I think you can use the IMemberManager to access your logged in members information...
https://our.umbraco.com/Documentation/Reference/Querying/IMemberManager/
There is a GetCurrentMemberAsync method I think you can use
And you can use AsPublishedContent to give you access to all the properties configured on your Member Type for the current logged in Member...
Regards
Marc
is working on a reply...