2

I am doing a mobile app with Angular and MVC. I am doing my app calling some dummy data from the json model in the web api. Check my code below:

 private IEnumerable<JsonModel> events = new JsonModel[]
    {
       new JsonModel {Id = 1, Title = "title1"}
       new JsonModel {Id = 2, Title = "title2"}
      };


        // GET api/<controller>
        public IEnumerable<JsonModel> Get()
        {
            return events;
        }

        // GET api/<controller>/5
        public JsonModel Get(int id)
        {
            return events.FirstOrDefault(e => e.Id == id );
        }

What I want to do now is to connect my project to the real database. How can I do that?

3
  • 1
    There are a zillion of possible answers to your question, and this is clearly too broad, and you want somebody to do your homework. Please do some research first, try something and if you have a concrete problem come back to SO. Commented Feb 9, 2015 at 14:49
  • Zencoder I have done my research. But I cant find much about this. I have added the database to my project, but I don't know how to access it :/ Thank you anyway Commented Feb 9, 2015 at 14:56
  • 1
    You should include all the research that you have done. What kind of database? what do you want to retrieve? how it should work? Commented Feb 9, 2015 at 14:57

2 Answers 2

2

As the ZenCoder mentioned, there are lots of ways to access your database, one of them is the repository pattern, here's some info about it:

https://msdn.microsoft.com/en-us/library/ff649690.aspx

This is one of the most famous patterns used nowadays and when working with the asp.net mvc framework is used with the Entity Framework. Here's a nice tutorial which explains how to use it with the ASP.NET Web Api2:

http://www.asp.net/web-api/overview/data/using-web-api-with-entity-framework/part-1

any question just let me know.

Sign up to request clarification or add additional context in comments.

Comments

0

Configuring access to the database file itself can be also the source of your isssue, look here: Configuring Permissions for an Access Database

Hope it helps

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.