On one server 2 databases have the same model and Context - asp.net

I have the following question
First, I have an Sql Server (MyServer), where I have two different databases (databaseOne, databaseTwo).
Then, I'm working in a ASP.NET MVC 4 project, and this is what I want to do:
I want to create my Model with all the tables from databaseOne, but also add in the same model all the tables from databaseTwo.
All I want is all my tables in the same context because I need to do several joins between databaseOne and databaseTwo. How can I accomplish this?
I have already created my Model for databaseOne, but how can I add all the tables from databaseTwo?

The only way to do this is to create views in db1 which make the joins between db1's own tables and the tables required in db2. You can then get the views in the model.
To update the tables in db2 I don't think is possible, but you can certainly read them via views in db1.

Related

Is there a better option than nested GridViews?

The question here is about using nested GridViews or to "pre-assemble" the data from two tables using an SQL UNION in order to display it with a single GridView so that it appears as shown on the image below.
I am working on an ASP.Net project for which I am developing a form to match data between tables in two databases (Well the tables could be in the same database, and it would not make much of a difference). I have an SQL stored procedure that pre-calculates possible matches. The form I am developing will display these possible matches to the user who will then decide which row in one database corresponds to what row in the other database. The matching is done based on data resemblance.
It will look like this:
The Search box is for retrieving a match by hand, if this is necessary. The Action column will contain buttons to perform the matching. But here, we don't need to care about these.
Of course, I could use nested GridViews or nested Repeaters to achieve this, but is it the proper way of doing this? It would mean to issue one query to the database to retrieve rows from database DB1 and then to issue one query to database DB2 for each row in DB1. Typically, there will be hundreds or thousands of rows in DB1; let's say up to 2000. Also, some people recommend using Repeaters over GridViews, but what if paging is required on the main data source (DB1 in my case)?
Since the information in DB1 and DB2 is similar, I thought I could use a UNION query to merge data from DB1 and DB2. I am able to do that, except I don't know then how I can do paging using this method. Using paging with this scenario, I risk having some DB2 matches for one DB1 entry split over two pages, and I want to avoid this.

Microsoft Lightswitch and Entity Framework Code First Inconsistency

I've begun investigating Microsoft Lightswitch 2011 as a possible solution for developing quick "admin" apps for updating various databases - primarily those containing lookup tables or configuration data for internal corporate websites or applications.
I have a website that was developed using ASP.NET MVC. EF Code First was used in building out the data layer. Some of the relationships are many-to-many which EF CF handles by creating a join table with just two fields containing the primary keys of the two tables involved in the relationship. The primary key of the join table is combination of the two fields. For example, a document entity can have many categories and a category can consist of many documents. Three tables get created: Documents, Categories, and DocumentCategories. DocumentCategories only has two columns: DocumentID and CategoryID.
When this database is attached to Lightswitch as an external database, and a master-detail screen is created for the Documents table (and showing the related Categories), data can be deleted from and added to the related table (the join table) but not modified.
Investigation revealed that Lightswitch requires a join table in a many-to-many relationship to have its own primary key that is not a concatenation of the keys of the related tables. In other words the table must be of the format: DocumentCategoryID, DocumentID, CategoryID. If the join table is structured that way, it becomes possible to update the entries in the related table.
I know that I can work-around this by not updating records and simply deleting and re-adding them. That's not a big deal since 1) Lightswitch makes that easy, and 2) there's usually not wholesale changes in the related data. It goes against my sensibilities though of "what's right".
So at the risk of providing fodder for all the Microsoft tool haters, 1) is this just a case of Microsoft making a mistake and not being consistent or is there some other force at work here, and 2) is there a way to "fix" this without having to rework my ASP.NET MVC, EF CF app and changing the database structure?
1) LightSwitch works. Yes there are 'haters' but then there were haters when nail guns came out ( http://jhurst.blogspot.com/2011/01/nail-gun-or-hand-nail-your-roof-which.html ) The end user who is paying for our services will demand that we use tools that can reduce costs by 90%+
2) Using WCF RIA Services allows you to place a layer between whatever you have going on in your data layer and LightSwitch (see: http://lightswitchhelpwebsite.com/Blog/tabid/61/tagid/21/WCF-RIA-Service.aspx ) Only use the 'data source wizard' when it works for you. If it gives you any problems then a WCF RIA Service, that will only take you 5 minutes to code up, will resolve any situation because you are able to drop into procedural code to handle any transform you need.

ASP.NET Dynamic Data: Access rights only to specific rows

I want to use ASP.NET Dynamic Data for my next project, but there is a problem a can't manage to solve. In the database we manage authorization on a per-row basis. For example no user is permitted to see all rows of the Contracts table. So there is a Many to Many Relationship between Contracts and Users. So everytime Dynamic Data performs a Select to show all Contracts it has to look into the ContractUsers junction table to see what contracts the current user is permitted to see (filtered by UserID which will be stored in a session variable). Of course these junction tables should be invisible to the users.
By default Dynamic Data returns all rows of a table, so is it possible to customize this behaviour for every query the user performs?
I want to use Dynamic Data together with LINQ to SQL but if this task would much easier to accomplish using Entity Framework I would look into that too.
Thanks for your help and time.
Implementing such a solution in Dynamic Data it will probably require the creation of a custom Entity Template; not really easy but once done it will not require the creation of custom pages just the editing of the page templates.
I think it will be really usefull to check the excellent work on DD done by S.J.Naughton and presented on his blog.
Greetings, F.
You should not use dynamic data because you need full control over querying and manually write all linq queries to add your data level security. If you still insist on dynamic data be aware that you will still write most of pages yourselves and you will only use dynamic templates. You will have to manually define ever data source and correctly pass where condition to filter results based on logged user.
In addition linq-to-sql is not able to hide junction table and entity framework is able to do that only if junction table contains just two FKs for many-to-many relation. If this table contains any other column you want to use in the application you will have to map it as any other entity and dynamic data will show it as an entity.
Dynamic data are technology for quick creation of simple application where you need to provide access to database through web interface but what you describe is not a simple scenario. You need per record authorization which can differ among entity types.

ORACLE-How to manage rdf schema and instance data in multiple tables?

I need to store the rdf schema in one table and rdf instance data in another table in ORACLE.
How I can do this?
How to configure the joseki-config.ttl to work for multiple models? Some example will help me to understand the solution.
Is there any possibility to create a single model for multiple tables?
Please let me know.
You need to use SDB with Joseki and Oracle. Then you can have a persistent datasets (a collection of models). There is an example of an SDB configuration in the Joseki download in joseki-config-sdb.ttl.
SDB controls the database table layout. A model is stored in the default graph name or in the named graphs table. There is no control for other layouts without changing the code of SDB.
Note that TDB, a custom database layer for Jena, scales better and is faster than using a relational database over JDBC. Fuseki is the new version of Joseki.
The Jena user mailing list is jena-users#incubator.apache.org.

Dynamic Data: Scaffolds are read-only for LINQ classes using Views instead of Tables?

I am trying to use the ASP.NET Dynamic Data features to generate CRUD scaffolding for my data model. My model contains supertype/subtype relationships, so some logical entities are split between two tables: one for the generic data and one for the subtype-specific data.
In the LINQ context I expose these entities as a single class, backed by a view that joins the tables together. I have also created sprocs for insert/update/delete and configured the class behaviour to use them.
When I turn on scaffolding, it only generates a read-only view of this data. The add, edit and remove links don't show up. Why?
SOLVED: The problem was that I did not identify a Primary Key column on the LINQ classes after dragging the views onto the surface. After adding a PK the CRUD functions showed up.

Resources