I am evaluating Xamarin and I am hoping to clarify that I am on the correct path.
We would like to create a Xamarin forms app with offline sync. We are using azure to host the backend database. I have created an Azure web app that uses as Azure SQL database.
I have seen example using easy tables, which seems to create the API’s for you but I cannot find any examples where an Azure SQL database is used.
I have gone to the quick start blade of my azure web app, selected Xamarin.Forms, then chose the backend language of C# and downloaded the project. The project included the TodoItems table as an example. Am I correct in thinking that I need to replace this code with the model of the tables I have in my azure SQL database? And then add the changes back to the web app to expose the tables so that the xamarin forms app can use?
Or am I completely on the wrong track? Should I be using swagger (which I have no experience with) to create the API?
Thanks.
From How to: Define a table controller, you could find that Data Transfer Object (DTO) class that is used to define the table within the SQL database need to inherit from EntityData class. And deriving it from EntityData class is aimed at making it support the system properties. It seems that you have created some tables in your Azure SQL database, if you’d like to expose these existing SQL database tables that does not contain these system properties, please refer to “Using an existing SQL Table” in chapter 3.
Related
Asking for your input. I have created a project athrough ASP.NET - CRUD with EntityFramework
We have to use Azure services for deployment.
This is my setup:
Created Azure SQL database.
Completed the table for the data to be stored (name, age etc.)
Create ASP.NET API and scaffold. Success. Was able to view my data on the localhost.
Created AZURE web app service and publish my API. Checking the url its working so okay.
Completed ASP.NET MVC, called my deployed API app service. Modified controllers, models and views for my webform.
Created AZURE web app service and publish my MVC. So working CRUD, success retrieval of data.
So now working on uploading image.
How will I incorporate the uploading of image for my user(for ex those who will check my project) using blob. Do I need to add the step during my creation of API since I scaffold it? I'm now confused about how I can include my image retrieval from blob storage in my setup or workflow. I just able to work in my crud and still studying for image retrieval.
I have seen tutorials with regards to incorporating blob in asp.net. The problem is that they have only this image upload function in their example. My case is I do want to incorporate it with my CRUD.
Thank you very much for your help.
Do I need to add the step during my creation of API since I scaffold it?
Asp.Net Core's scaffolding won't automatically help you integrate azure blob-related feature code.
If you want to use the relevant code in the auzre blob in the scaffolding, you need to combine the SDK or restapi to implement it yourself.
My aim is to develop a web app and a mobile app that share data from the same database.
What is the best way to achieve this (using azure)?
I think I should:
Create a Web App from Azure Portal with a SQL Database
Create a Mobile App from Azure Portal with an existing Database (the one I created before)
Then I'll develop my ASP.net MVC project, using Entity Framework to create the db Schema and I'll publish it in Azure.
Finally I'll develope my mobile app (in this case I would like to use Xamarin) and I'll access to the database (created before) using the code for Easy Tables.
Is it right? Or I'm thinking wrong and this isn't the best architecture to share the same database between a web app and a mobile app using Azure?
This should be fine. Keep in mind that the Azure Mobile Apps server will automatically add some system columns to your database tables (createdAt, updatedAt, deleted and version). Also, a limitation of Mobile Apps is that the primary key name must be called id.
If you want to develop the web site and mobile app share the same database, it is a good choice.
Azure Mobile Apps is a plain old ASP.NET application or Node.js application. Easy Tables is simply a projection of data from the Node.js version. If you are using ASP.NET, then you don't get Easy Tables.
That being said, it is relatively easy to add Azure Mobile Apps SDK to an EXISTING web app.
1) Copy the code from App_Start\Startup.MobileApp.cs and Startup.cs from a sample app to your ASP.NET app
2) Ensure all your models inherit from EntityData so that they are "mobile ready". If your models already have an auto-incrementing Id column, then see https://shellmonger.com/2016/05/11/30-days-of-zumo-v2-azure-mobile-apps-day-19-asp-net-table-controllers/ for a workaround
3) Scaffold Azure Mobile Apps Table Controllers for your mobile database table projections.
You can use the same models across both MVC controllers and Mobile controllers. If your app uses AJAX calls for getting data, you can replace those AJAX calls with the JavaScript SDK for Azure Mobile Apps so you don't have to duplicate things.
The main place you are going to have to work on is integration of auth. Most MVC applications use an Identity database because they have grown it from one of the existing MVC templates. You are going to need to implement a custom mobile auth mechanism to re-use the database. You can find information about this on the azure.com HOWTO documentation.
I've been studying Xamarin.Forms with goal of building cross-platform mobile app in VisualStudio2015. I've got a perfectly acceptable public facing web site but native app(s) are what the boss thinks we need.
The current web app hosted on IIS 7.5 uses a separate project(DLL) for database access to an on-premises SQL Server 2008 instance. This VStudio project exposes domain objects to the calling ASP.NET webforms by executing various stored procedures using System.Data.SqlClient.
I know building the mobile native app itself with Xamarin.Forms is one part of the challenge but I am asking here for clarification about how to approach the database requirements:
Do I need to create some sort of web service that provides the same CRUD functions required by my current web site?
Xamarin documentation lists several options for consuming web services and the more I search and read about data access I conclude that a callable web service of some type is going to be required for my eventual native mobile app.
Is this assumption correct?
Yes. You generally want a webservice layer brokering requests between your mobile app (or any remote client) and your DB server. If you already have all your crud operations in a separate library that is utilized by your website, then a webservice would just be another set of endpoints that rely on the same CRUD library.
I'm actually working on an university project and have to figure out how to connect my windows azure database to an already existing ASP.net web application project.
The web application should run on smartphones and tablets.
Since this is a group project, we use TFVC to manage the project.
Our client supplied an mysql script that will create the tables needed.
The Database is hosted in Azure and we want to access it through Visual Studio ultimate, so we can reveice data from the DB and integrate it's data in the application.
I also got the connection string, so I could use it if needed.
So my question is:
How can I connect to the database through visual studio and afterwards: how can I access to it? With access I mean, how and where can I use SQL queries in Visual Studio?
I don't really know where to start, whether it is connecting to the DB via code or on another way.
Every kind of help is welcome.
Thank you in advance.
Your question is still quite vague on specifics of what you want to achieve but hopefully this answers it. If not, please provide even more detail on your question.
If you just want to see the DB in Visual Studio and interact with it
Download the Azure SDK
Go to Tools > Connect To Database
A side box will open and you can navigation through Azure then to your database.
Personally I prefer using SQL Server Management Studio, its much more responsive that the UI through Visual Studio.
If you want to connect your application to Azure, as in code an application that talks to a database, then you just need to replace the connection string in your Web.Config to your Azure Connection String. Then either use ADO.NET, Entity Framework or another ORM.
I recommend Entity Framework but it all depends on what your circumstances and project requirements are.
If the DB already has its schema defined get started here:
https://www.asp.net/mvc/overview/getting-started/database-first-development/setting-up-database
If its empty you can use code first:
http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
When creating a new Silverlight 5.0 business application, the authentication and authorization code is automatically generated. All the user info and roles are by default saved in the aspnetdb mdf file. My questions are:
Is it normal practice to keep user authorization/authentication data in separate database from your business related data, or should I copy the tables into my main database? I see that current implementation involves ApplicationId field, so it means that it can store data for different apps? Maybe there is some common database on the web server for all Web apps (just guessing)? :)
If I am to keep the user's info in a separate database, how to relate the data between these two databases? I mean, I will have UserId referenced in some tables (business rules)? My business data is using identity PKs and aspnetdb is using UniqueIdentifier, is this a problem?
When a user registers on the site, how do we assign it roles in production? There is a ASP.NET Configuration tool within Visual Studio, but what about the production environment? Should this be coded in the Web project?
What is the best practice for handling authorization / authentication of users in cases where the application always require authentication?
You shouldn't use the defaut ASP.NET authentication implementation in your production App: It uses a local database (the mdf file) because it works out of the box. However, You are not limited by this solution:
You could configure ASP.NET authentication (and role) provider to use your real database, allowing you to better integrate it into your existing data. To better understand the full process, see http://msdn.microsoft.com/en-us/library/6e9y4s5t.aspx and the linked pages. ASP.NET is able to generate all the required tables in your db by itself.
You could override the default authentication mechanism with your own. In this case you only have to edit the Services/AuthenticationService.cs in your web app project. The AuthenticationService class inherits from AuthenticationBase, and allows you to override quite a lot of membership methods with you own implementations.