Why must I include the Telerik ORM assembly in my MVC project when I have already included the Data layer?

StackOverflow https://stackoverflow.com/questions/21081134

Question

I'm trying to get a simple example of Telerik ORM running on my site. I have a DAL which is a separate Visual Studio project.

I also have an MVC5 application. Both projects are tied to a single solution. Pretty standard setup.

In my DAL project, I have a simple repository that returns an object of type Topic that is retrieved from the DB. My code looks like this:

Repository:

public class Repository
{
    public Topic Get(int id)
    {
        var fluentModel = new FluentModel();
        return fluentModel.Topics.Where(t => t.Id == 1).FirstOrDefault();
    }

}

Topic:

public class Topic
{
    public int Id { get; set; }
    public string Headline { get; set; }
}

When I call the repository in my controller:

public ActionResult Index()
{
    var repository = new Repository();
    Topic x = repository.Get(1);    
    return View();
}

At compile, my MVC project is throwing an error. I need to include the Telerik.OpenAccess assembly to stop the error. I've already included my Data assembly in my MVC project, so I'm curious why my MVC project cares? I'm simply returning a Topic. Why does my MVC project need access to Telerik.OpenAccess? How can I avoid this. I don't want my MVC project to know about Telerik.

Était-ce utile?

La solution

Telerik OpenAccess ORM uses a post-build step injecting code in your model assembly providing the persistent capability, change tracking and lazy loading functionality.

This is achieved by a tool called OpenAccessEnhancer and in order to consume the enhanced project you need the Telerik.OpenAccess and Telerik.OpenAccess.35.Extensions assembly references in your MVC project (as well as in any other project consuming your model).

Here you could find the full configuration for consuming Telerik OpenAccess ORM Fluent Model.

Regarding an example of Telerik OpenAccess ORM - I suggest you take a look at the end-to-end examples in the OpenAccess Samples Kit and especially its ASP.NET MVC section. You could find the recommended approach for the UnitOfWork, Repository and Service patterns implementation in the AJAX With Data Annotations sample application.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top