Local Database in Silverlight - wpf

I want to integrate a local database into Windows Phone 7 project. The DB should be allready filled with values from manual input.
Therefore I use a wizard to create a local Database in WPF.
I can create tables, set their values and fill in them, but I could not find the way how to refere columns from different tables.
Is it possible using UI wizard in Visual Studio or only possible by coding the datacontext?

It is possible what you ask and the easiest way to do it is Linq to Sql.
Database Management in Mango
There is an easier way to do it but i think ms doesn't support that, you create a new windows WPF project and there you add a LinQ to SQL database model there you can create your database and then just copy it to your wp7 project and include it in the solution.
Then you will have to comment out or delete the two constructors which are not supported by the WP7 and your are ready to use your database.
The two constructors to comment out use System.Data.IDbConnection connection
This solution is explained in detail in Corrado's Blog

Related

How can I connect to my SQL Azure-database using Microsoft Silverlight?

I have a database online at Windows Azure. I want to connect to the database and show some tables in Microsoft Silverlight. I have created a Silverlight Application and published the website on Azure here!
How do I connect to my SQL Azure database in Silverlight?
The same way as connecting to any other database!
Personally, I use EntityFramework and create my own service. You can use EF and use RIA Services to create a lot of code for you though if you prefer.
Add an Entity Model to your project, create from existing db, point at your Azure Db, job done. Remember to add your existing IP to the Azure firewall while developing.
EDIT:
Try following this tutorial instead:
http://msdn.microsoft.com/en-us/library/ee707376(v=vs.91).aspx
BUT one thing to watch out for. When you come to the step to add a DomainService, if it hasn't picked up your context you will need to follow the steps listed here:
http://support.microsoft.com/kb/2745294
... which are easy to follow. Delete the TT files and change the model code generation strategy from none to default.
One thing that you can do is create a WCF project, which will act as your Web Role in Azure.
Ideally, you may have 2-3 projects in your solution:
1) Silverlight Project (Presentation Layer)
2) WCF Project (Business Layer)
3) C# Class Project for your Sql Connections (Data Layer)
What you would be able to do is use C# .Net libraries for Sql to connect to your database. You may either execute stored procedures (Can pass in variables), which are cached in memory for faster long-term performance, or Sql queries in a string variable, to pull the exact information you want in custom queries. This would be returned to the WCF Project in which you would be able to perform any custom business-logic and you may begin to package your data into class objects. These objects may be passed back to Silverlight via a Service Reference, and you may use many familiar Silverlight tools to display your information.
The above recommendation may be a more more in-depth than that of the other recommendations, but in cases where you really need control over your data and need to apply business logic, this is a good way.
The easiest way in the world I know of to hook up a SQL Database to a Silverlight application is to use a Visual Studio LightSwitch project. There are ton's of posts on how to do this - http://blogs.msdn.com/b/lightswitch/ . Basically if you make a LightSwitch application (available in VS Professional SKUs and up), it gives you several screen templates to choose from which are all Silverlight (or HTML 5 if you choose). Then you can "attach" to an existing SQL Database such as SQL Azure just fine. And make browse or edit screens around the SQL data.
You can optionally model your own SQL Database and then "publish" it out to SQL Azure.
You can do all of this without writing any code too and provides some good basic functionality.
HTH - Matt

How to allow user to select an existing database or create a new one?

We have a desktop application built with WinForms in 4.0 framework. A single user can install the application and use a local SQLExpress installation. Or, the SQLExpress can be on another machine on the network. We want to give users ability to create new database(which will execute a sql script which will create the required structure) on any server instance. Is there a control which we can used to accomplish this? Or, what are the ways to accomplish the aim?
if you're using an ORM (such as nHibernate)- then these abilities come out-of-the-box.
otherwise- you can write stored procedures that build the desired database.
this is a little more tricky, but possible.
here is a good start on DDL.

Entity Framework; updating DB from Model?

In mySql Workbench there's a possibility to "sync" the model with the DB and vice versa. Is there a function like this in EF? I've added som entities and I'd like it to get reflected in the DB. Do I really have to regenerate the entire DB and loose data?
Thanks
Sadly there is no easy way AFAIK to do this today.
One way to handle this is to generate the DDL and then cut and paste the new sections into SQL Server Management Studio and run them there. If you want to maintain scripts for each release of the database you'll need to take an approach like this too.
See also: Database migrations for Entity Framework 4
PS The EF Power Pack: http://msdn.microsoft.com/en-us/data/ff830362.aspx may help. It says "The second useful feature related to model-first the ability to update an existing database and synchronize the model with it. This allows you to make changes to the model that can be deployed to the database without data loss."
if you are using the VS2010 then in Select your edmx designer ( designer showing tables) and right click it will show the update model option.

WPF application with MS Access database as a data source

I have a Microsoft Access 2010 database(*). Now, using Visual Studio 2010, I want to create a WPF application and add the database as a data source. The app will have a window with a frame that provides navigation through pages. No problem so far. But:
-What is the right way to set up the database in this scenario? Tables only? Or must everything go via queries? (VS2010 talks about views which I assume (?) are queries)
-Database data must be updatable and records can be added. Some relationships go through link tables (many-to-many) and there are nullable foreign key relationships. Must I take manual steps to make it work?
-While adding the data source VS2010 created an xsd from my Access database. I think the xsd might need further tweaking for the application to work the right way. What if I change my Access database design, I'd have to regenerate the xsd again as well. Is this right, and is it the way it is usually done? OR, should I let the original Access database go and give the application the capability to create new empty databases?
-How do you provide controls in a page to step through the records in a table? Is there a special database control?
-What is the way (WPF class?) to load records into the data context that displays in a page? (At this level it probably does not matter what type of data source it is.)
(*) A single user desktop database
This is not the exact answer to the question. But an alternative.
Is this a single-user database?
You can try this better and highly efficient combination:
SQLITE (DataBase)
DBLINQ (ORM)
LINQ(a .NET framework component for querying the db)
You should also take a look at ObservableCollection, DataBinding and DataGrid in WPF toolkit.

How do you generate a database schema diagram in visual studio (express)?

Right now all I did was use the Dataset designer and dragged tables into it from the Database Explorer. It works (for what I need anyway) but it feels like it's a misuse of Datasets. (Actually I'm not really sure how to use Datasets or what the intended usage is, I was planning on using LINQ2SQL to interact with the DB)
Is this ok? I only need it for the designer view and it's a very simple DB layout (just 4 tables). I'm sure there's other tools out there, but is there anything integrated into VS Express that I should be using instead?
You download MS SQL Express with the SQL Studio Management Studio Express. Only in the Studio Express can you connect to the server, select the database, open the database diagrams and edit diagrams.
Then, you can drag and drop the entire set of Tables in to Linq to SQL. Entity Framework is nice, but I have yet to get it to render my tables well yet. I would stick to Linq to SQL until they release another upgrade to EF (easier for you).
You say it works, and you want just want to make a diagram, so go with it. You should make sure it doesn't build the generated code file, however, as it could cause bloat in your final product.
If you're not going to use it for code and it provides adequate output for you, what does it matter if it's a "misuse"? I know people who used Excel to design documents because it was easier to line things up that way. I would use Word, and it's clearly not Excel's stated main purpose, but does it mean using Excel was wrong?

Resources