Entity framework database first best practice for managing a DB - asp.net-mvc

i would like to know if there is someone that can help me find the best way to manage a db with 50 tables that i assume has to be structured in my mvc application as multiple EMDX files for performance but that will have multiple connection strings that i hate.
So let's make a short example:
i have a join of 5 tables to create a customer list grid
and another 3 tables join for an employee grid.
I created two edmx context files to manage each grid and i have 2 connection strings.
Now, if i haev to create 30 grid will i have to create 30 edmx files and corresponding 30 connection strings?
The question is: is this the best practice for this? duplicating 30 times the connection string that connects to the same db?
Thanks

I am not sure why you need separate connection string. If you are connecting to same database then one connection string is enough.
Also if i understand correctly you are creating separate edmx file for each grid. This is not correct way of using Entity Framework. You should be using only one EDMX file for a database, 50 tables is not a big number. If you have complex query then i'll suggest to use store procedure and call it via Entity Framework using function import

Related

Compare between two databases have the same tables

I have 2 databases, each of which has 2 tables, Employee and Department.
One of them is old and the other one is the new one.
I want to compare the data between them. I have make DTOs classes and mapping between entities and the DTOs classes using Automapper.
Can anyone help me step by step to compare these databases using EF?
Compare the data from old database to the new database.
Depending on the comparison show result in one of four groups:
Data already exist with no change
New data ready to be moved
Data to be updated
Data to be deleted
Then I can deploy the changes to the new database

Custom fields using Entity Framework 5

I'm starting to write a project and its my first time using ASP.NET MVC and Entity Framework (since now I've used PHP for around 5 years).
I got categories and posts, each category has to have its own unique filters that can be strings or Booleans (I'll get them via textboxes or checkboxes). I'm starting to get confused when designing the entities.
I'm using code-first approach but don't know how to set-up custom fields in Entity Framework. If I'd design that in PHP and pure SQL, I think that in order to keep it perform good, I'd create extra columns on the fly (e.g. "filter_1", "filter_2") and then create mapping table that contains the description of the field, the type, etc. and I didn't figure out if this kind of implementation is possible in EF.
I've thought about some options:
- I can create the filter using many-to-many relationships when creating a filters and filters-values tables and when creating a post add the filter values into that table. The main con about it is he performance - I'll most likely have 40k+ rows and more than 20 custom filters for sure... so searching and data fetching will be too slow...
- I thought about serializing the filtered values into some form of content, for example into bytes array and then only desterilize it - but the problem is that I won't be able to search within that...
- I can use the traditional ADO.NET way in order to create my initial idea (that I've described when talking about PHP - using the "filter_N" columns) but that'd create too much mess with EF...
There's any other way to achieve my goal (to create custom filters)? any way to create custom fields using EF?
Thanks for your help!
I don't know of a good way offhand to implement this in the Entity Framework. If you really wanted to use the Entity Framework I believe you could design your database tables in such a way that you wouldn't have to create the extra columns on the fly. You could have separate tables to hold the filters and relate them back to categories.

In Entity framework 4.0 how can we fetch multiple record set from database in one call & pass all data to View

In Entity framework 4.0 how can we fetch multiple record set from database in one call like we do in ado.net dataset?
Soppose we have 3 table T1,T2 and T3. We need to fetch data from all tree table and pass to view(ASP.NET MVC3). No JOIN is to be used as all are independent table. Instead of making 3 call to database we want to wrap up all select statement in one SP and make only one call to database and pass all data to view.
In case of dataset if stored procedure return data from multiple select statement dataset populate each recordset in different table.
How can we achieve it in EF? Please help me.
Thanks,
Paul
There is no out of the box feature to batch queries in EF. But there are some efforts made by others to extend EF to support this.
Entity Framework Batch Update and Future Queries
MultiQuery
(more queries in one batch) in Entity Framework using LINQ

Ruby dynamically tied to table

I've got a huge monster of a database (Okay that's not quite true, but there are over 8 million records in one product table)..
This table is fed by 13 suppliers.
Even with the best indexing I could come up with, searching for the top 10,000 records that are ready for supplier 8, is crazy slow.
What I'd like to do is create a product table for each supplier and parse the table into smaller tables.
Now in c++ or what have you, I'd just switch the table that I'm working with inside the class.
In ruby, it seems I'll have to create a new class for each table, and do a migration.
Also as I plan to have some in session tables #, I'd be interested in getting ruby to work with them..
Oh.. 8 million and set to grow to 20 million in the next 6 months.
A question posed, was what's my db engine.. Right now it's sql, but I'm open to pushing my db to another engine, if it will mean I can use temp tables, and "partitioned" tables.
One additional point to indexing.. Indexing on fields that change frequently isn't practical. Like price and quantity.. I'd have to re-index the changed items, each time I made a change.
By Ruby, I am assuming you mean that inheriting from the ActiveRecord::Base class in a Ruby on Rails application. By convention, you are correct in that each class is meant to represent a separate table.
You can easily execute arbitrary SQL using the "ActiveRecord::Base.connection.execute" method, and passing a string that is your SQL query. This would bypass having to create separate Ruby classes that would represent transient tables. This is not the "Rails approach", however it does address your question of allowing switching of the tables inside a class file.
More information on ActiveRecord database statements can be found here: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html
However, as other people have pointed out, you should be able to optimize your query such that splitting across multiple tables is not necessary. You may want to analyze your SQL query's execution plan using various tools to optimize the execution. If you are using MySQL view check out their query execution planning functionality: http://dev.mysql.com/doc/refman/5.5/en/execution-plan-information.html
By introducing indexes, or changing join methods between tables, etc you should be able to return reduce your query execution time.

How do you query multiple databases for one view in ASP.NET MVC?

I have three databases, x, y, z. Let's assume MS can speak to all of them via odbc or something else.
When I was in webforms I would create a tableadapter and conduct a query. I could do this for each connection I had, so I had three queries.
I would drop each connection and dataset on my page. Each control I used would call the appropriate dataset and populate it's gridview or whatever. All was well. I had three databases, three hits, all on the same page, for one integrated page for the customer.
How can I do this same thing in ASP.NET MVC? Please.
Thank you.
You get your data from your databases and return all the results in your ViewModel
the simplest way would be to get it all in your controller, assign it to your model the send it to your view
Using ASP.Net MVC entity framework, create entity classes for each of the 3 databases (Here it's assumed that you are querying entirely different tables from 3 different databases). What you get here are 3 entity classes, each having it's own properties that directly correspond to the table column names you are retrieving. Now, you don't need to worry about 3 databases. Entity framework abstracts it into a set of properties that map into different tables in x,y and z databases you are retrieving from.

Resources