Thinktecture IdentityManager choosing a db schema - thinktecture-ident-server

I recently setup a dev site and am using IdentityServer3 with IdentityManager, both from thinktecture, and IdentityManager is designed to create the database for itself, but can be configured to work with an existing db. I was able to get IdentityManager into a local db I had previously created with the default schema, but I would like to switch it to a new schema. Basically the question is that I can't figure out how to set the desired schema in the db in IdentityManager and can anyone in here give any insight?

There are many ways to do this (idsrv3 is very configurable). A common way is to add the MembershipReboot package, subclassing the MembershipReboot factory classes, and then loading your new factories during the idsrv3 startup. You will also need the IdentityServer3.MembershipReboot project, which acts as a go-between between IdentityServer3 and MembershipReboot.
In the visual studio package manager console you add the projects like so:
Install-Package BrockAllen.MembershipReboot
Install-Package IdentityServer3.MembershipReboot
You can use the idsrv3 samples as an example of how to set up your classes. https://github.com/IdentityServer/IdentityServer3.Samples
That will give you the data entities you need. Then to write your entities to a database, add the MembershipReboot.EF project and set up a database connection string that gets passed to your override of the MembershipRebootDbContext() class.
Install-Package BrockAllen.MembershipReboot.Ef
The first time you start your identity server, MembershipReboot.EF will use Entity Framework to automatically create your database schema and start writing your entities there.
Hope that gets you started, sorry if it's not what you're asking!

Related

How can I connect to an external SQL database using Blazor without using packages (like Entity Framework)

I'm not even sure if this is possible but Google has been unable to help me. It may just be because Blazor is so new. Anyway, I've got a premade database and I want to connect to it directly like how you can open a connection, run some SQL, then close a connection in ASP.NET. I, unfortunately, can't just make a new database using code-first as most tutorials tell you to do.
Two options that spring to mind is the Entity Framework Core (Database First) or Dapper.
I'm actually connecting to an existing database using Dapper in my Blazor projects and there are better Dapper examples/tutorials available however the below is a basic example.
https://github.com/DotNetDublin/BlazorServerSide/tree/main/BlazorServerSide
If you don't want to use either Entity Framework or Dapper you can use ADO.NET.
The below tutorial is for MVC however the code for interacting with the database would be the same. See StudentDataAccessLayer.
https://www.c-sharpcorner.com/article/crud-operations-using-asp-net-core-and-ado-net/
use the ef command Scaffold-DbContext

EDMX generated with ODT/ODAC, context class not showing in Domain Service Class

I am following an msdn walkthrough for creating an RIA services solution with Silverlight. Here is the article link. I have followed at least 4 other articles and found like a dozen more over internet but all of those create edmx from SQL server. In my case, I have to use Oracle in backend, so I have created the data model through Oracle Development Tool, Oracle Provider for .Net.
After generating the edmx and building everything,
I move on to create a domain service class to use the classes in silverlight project, but for some reason the context class doesn't load in the dropdown where it should.
A sample class generated by the edmx looks like this
I have been trying to do this for a week now, and after having been tried for half a dozen times, I need help.
If you are using Visual Studio 2012 have a look here:
http://support.microsoft.com/kb/2745294
In summary:
Open your entity model in the designer (If needed, click in the "white space" of the designer to ensure no objects within the model are selected)
In the Properties window, change the "Code Generation Strategy" from "None" to "Default"
Delete the two ".tt" files that are adjacent to the model, with the assumption that you have not modified these files beyond their original state when the entity model was created. If you have modified these files, then customizations to your entity model will be lost.
Rebuild the project

ASP.NET MVC 4 Code First Solution Setup Using SQL Server 2012

I am planning to create a web application using ASP.NET MVC4 using the code first approach.
I am using Visual Studio 2012 and I have SQL Server 2012. What I would like to do is setup the solution in a way that I can use SQL Server instead of the default being SQL Express or localDB. I would like to have the solution regenerate the database if any changes are made to the models and seed the database with some test data when that occurs.
I have gone through a bunch of tutorials and they all seem to be using the SQL Express or LocalDB database. I was able to get the solution to generate the database on SQL Server the first time it was run, but after I make changes to the model such as alter the schema name from 'dbo' to lets say 'test' or change the table name, it doesn't seem to pick up those changes.
Can anyone give me some insight on how I might be able to accomplish this?
Thanks
All you need to do is have your connection string in the web.config pointing to your SQL server for it to use that server instance.
As for having it update on model change, have a look into DropCreateDatabaseIfModelChanges.
In your Global.asax you can set your database initializer like this
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DbContext>());
You will need a using statement too
using System.Data.Entity;
There is a free video guide to MVC4 by Scott Allen which can give you more info on Migrations and Code First (which is what you are asking about). The 4th section of the video guide has a 13 minute segment on Data Migrations which is a full walk through. If you can spare the time, watch that for a full detailed guide.http://www.asp.net/mvc/videos/pluralsight-building-applications-with-aspnet-mvc-4
I might point out this is only useful in development and there is no way to make it work for production as you would lose your data. If you need something that is suitable for a production environment look into SSDT (SQL Server Data Tools). You can manage your database as a SQL project in your solution and deploy updates using a DACPAC file. The file manages all the updates in production and can be set to protect against data loss. You can change and deploy your Db from your project and still use EF with database first and EF models etc. All you do is make your changes in the Db project and hit debug to update your test Db. When publishing you can choose to export the DACPAC for updating live.

Handling database migrations when using Entity Framework

We are building an app in C# which uses Entity Framework with SQL Server 2008. We design the model using the designer in Visual Studio and auto-generate entities from this.
We're working on version 1.0. When we release 2.0, we'll need to make changes to the model and underlying database structure. I guess we need what's called "database migrations".
Traditionally, I've had a table in the database called something like 'version'. Whenever I've created a new version of my software, I've created database upgrade scripts containing ALTER TABLE statements. My software has checked the version table and run the upgrade scripts needed to upgrade the database to the 'software version'.
Is there some better way of handling this? It would be nice if I didn't have to write the alter table-scripts myself and write my own software to upgrade the database structure.
What I used to do when I did model first, is I pointed my model to a database that was purely for schema (so I had a myapp database, which was where my app ran, but my EF4 model was outputted to a myapp_schema database). When the myapp_schema was updated, I used Db Source Tools to generate the update scripts and make the myapp's database schema be the same as myapp_schema.
Chech this post out. It's about CTP4 of EF4, but it thing this is what you need.
http://blogs.msdn.com/b/efdesign/archive/2010/10/22/code-first-database-evolution-aka-migrations.aspx
Unforunately this isn't yet available. CTP5 was released a few days ago and as far as I know this is not yet included.

Does nHibernate allow drag and drop automatic class creation like linq to sql?

Just a basic question. Learning Linq to SQL and some nHibernate. I am using the mvc tutorial and they drag and drop tables onto the visual studio designer to create the classes and wire up everything.
When I experimented with nHibernate I had to do lots with xml files. Does nHibernate have anything that is "easy" like Linq to SQL or is this drag and drop for Linq to SQL so basic that when I want to do something "real" it won't matter that Visual Studio does this for me (at this basic level)? In other words, the further I go with Linq to SQL, I'll eventually have to handle config files like I do with nHibernate.
Look at Castle's ActiveRecord framework. It replaces the use of XML config files with the use of Attributes directly on the class/property declaration. Also, a tool called ActiveWriter integrates with Visual Studio and allows connecting to a data source and generating the object model!
There is no "native" support like you see with LINQ to SQL. However, there are third party add-ins that will allow you to do something similar with nHibernate. My favorite is this one:
http://sourceforge.net/projects/nhibernateaddin
To use it:
Create a data connection to a
database that contains the structure
you are going to code against (your
development database).
Add a new NHibernate plug-in item
(via add new item) to your project
that will contain you domain objects.
In the property window add the data
connection string from the data
connection you just created (this
isn't automated yet).
Finally, you drag and drop your tables
from your data connection to the
NHibernate plug-in object and when
saved your mapping files and you
domain objects are generated. To use
it you create a data connection to a
database that contains the structure
you are going to code against (your
development database).