Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get data json from sql 2016 to angular 2? #51

Closed
meninjanho4788 opened this issue Feb 9, 2017 · 2 comments
Closed

How to get data json from sql 2016 to angular 2? #51

meninjanho4788 opened this issue Feb 9, 2017 · 2 comments
Labels

Comments

@meninjanho4788
Copy link

Thank you Sir.

how to apply this example in link below to this project.
https://www.codeproject.com/Articles/1106622/Building-REST-services-with-ASP-NET-Core-Web-API-a

it get data json from sql 2016 and not use model, response, interface in server.

@asadsahi
Copy link
Collaborator

@meninjanho4788 the project demonstrate Azure sql storage rather sql 2016.

As I understand, In order to access azure sql storage you need to register custom services in the project to get access to command and query:

public void ConfigureServices(IServiceCollection services)
{

    const string ConnString = "Server=db.database.windows.net;Database=TodoDb;User Id=usr;Password=pwd";

    services.AddTransient<IQueryPipe>( _=> new QueryPipe(new SqlConnection(ConnString)));
    services.AddTransient<ICommand>( _=> new Command(new SqlConnection(ConnString)));

    // Add framework services.
    services.AddMvc();
}

Then use these services in controller:

public class TodoController : Controller
{
        private readonly IQueryPipe SqlPipe;
        private readonly ICommand SqlCommand;

        public TodoController(ICommand sqlCommand, IQueryPipe sqlPipe)
        {
            this.SqlCommand = sqlCommand;
            this.SqlPipe = sqlPipe;
        }

// GET api/Todo
[HttpGet]
public async Task Get()
{
    await SqlPipe.Stream("select * from Todo FOR JSON PATH", Response.Body, "[]");
}
}

Same works for other CRUD operations. From Client side, it should be same setup to call these restful enpoints. I have never used Azure sql database. Perhaps above explanation will point you to right direction.

Closing this because of unrelated to this project.

@meninjanho4788
Copy link
Author

Thank you for your comment, sir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants