I want to create an umbraco repository which will stand for a dal level in mvc (data access level implementation). Can sb provide other ways of how to create it, not using umbraco helpers ?
public class UmbracoRepository
{
UmbracoHelper _helper;
public UmbracoRepository(UmbracoHelper helper)
{
_helper = helper;
}
public List<NewsViewModel> GetAllNews()
{
var newsList = _helper.Content(Guid.Parse("1d770f10-d1ca-4a26-9d68-071e2c9f7ac1"))
.ChildrenOfType("blogpost").Where(x => x.IsVisible()).ToList();
You should use an extension method for creating this
public static class UmbracoHelperExtensions
{
public static IEnumerable<IPublishedContent> GetAllNews(this UmbracoHelper umbraco)
{
return umbraco.Content(Guid.Parse("1d770f10-d1ca-4a26-9d68-071e2c9f7ac1"))
.ChildrenOfType("blogpost").Where(x => x.IsVisible()).ToList();
}
}
The problem with the solution above is that it will access all your published content. If you publish a lot of blogposts, then every page you use the method on, will have to handle all the posts. This can cause performance issues down the line.
I would suggest searching for the posts instead, and use paging to only show the posts you need.
Umbraco Repository
Hi
I want to create an umbraco repository which will stand for a dal level in mvc (data access level implementation). Can sb provide other ways of how to create it, not using umbraco helpers ?
Regards ^^
Hi,
You should use an extension method for creating this
The problem with the solution above is that it will access all your published content. If you publish a lot of blogposts, then every page you use the method on, will have to handle all the posts. This can cause performance issues down the line.
I would suggest searching for the posts instead, and use paging to only show the posts you need.
HTH :)
is working on a reply...