Is there a way to use Entity Framework 6 with DbUp without having 2 connection strings?
The problem is EF uses a conn string with a bunch of meta data for locating the model that DbUp doesn't like - it expects a simple conn string.
And EF doesn't run without all the meta data.
I could have 2 different connection strings but that seems just wrong.
You can use Code Based Modelling (Code "First") - that only uses the standard ADO.NET connection string
Related
I am using ASP.NET MVC with EF 5.0. I am trying to create a dynamic query and execute it using EF.
What I tried
var sConnection = ((SqlConnection)DbContext.Database.Connection);
sConnection.Open();
Thought I will take the EF connection and use that and execute the query and get result in DataTable.
But I saw other option of
DbContext.Database.SqlQuery //But I need to have Entity Type to get the results
DbContext.Database.ExecuteSqlCommand
Is there a way I can execute and get results to DataTable without using my way of getting connection object ?
Any other alternative and best approach wil be useful,
Thanks
i am new in MVC and entity frame work and i want to create Code first entity frame work.
we have already created project in asp.net and we want to migrate in mvc. we have lots of stored procedure and some procedure return complex data combination of 10 to 12 tables...
As a Proof of Concept we wan't to develop 3 to 4 pages...
i have some question regarding new start.
1) Should i used entity frame work if yes then which is better entity frame work model
Database first
Model first
code first
2) how to integrate stored procedure in Code first model
3) in each page we have minimum 7 to 8 table result there... how i will handle in entity frame work.
this is my first project in mvc and entity framework please help me with appropriated answer.
first, this has nothing to do with MVC. this is purely a data access issue.
second, this is sort of missing the point of using entity framework. if the goal is to migrate away from stored procs that one thing, but to use EF and continue to execute the stored procs defeats the purpose of using a ORM like EF.
Instead for your procs I would stick with raw ADO.Net, or use Dapper.Net to convert the stored proc result sets into objects.
EF would be a better choice as your convert each proc into EF linq queries. It's not that you can't execute procs (or raw sql) from EF, but it doesn't make much sense. Especially with how you describe the procs.
Recently I was working on an asp.net mvc 4 application and when reviewing the application I noticed I had 2 connection strings that pointed to the same database.
ApplicationServices - For membership related stuff
MyDbEntities - For entitry framework related stuff
I know you can make the entity framework context point to the applicationservices connectionstring like below I guess
public MyDbContext() : base("name=NameOfYourConnectionString") // Name of your connection string
{ }
Is there any performance difference between having one connection string vs defininf multiple connection strings? Or is ASP.NET smart enough to know the database is the same and will share connection when need be?
Regards DotnetShadow
Is there any performance difference between having one connection
string vs defininf multiple connection strings?
The ADO.NET connection pool is per connection string. There will be a difference only if the connection strings have some differences. In this case you will have 2 different connection pools instead of reusing connections from the same pool which would have been better since you are hitting the same database. But if the 2 connection strings are strictly identical, there will be no difference.
I have an Entity-class having a Property of type Int32: on generating DDL using DevArt for ORACLE a NUMBER(10) column is generated. Reading and writing instances works flawlessly.
However, on fetching instances of this Entity-class sending a custom query to ExecuteStoreQuery on the ObjectContext this Property seems to be returned as System.Double, as such constructing the instances fails.
Can I hint DevArt to construct System.Int32?
Thank you.
Bart
The reason is the fact that OracleDataReader, which is used in the ExecuteStoreQuery method, has type mapping different from the one used in the Entity Framework provider.
I recommend you to use NumberMappings, I suppose you will need to map Number(10) to Int32: Number Mappings=((NUMBER,10,10,System.Int32). These changes should be persisted to the model connection string (they are duplicating the default EF mapping rules, it is necessary for the OracleDataReader from ExecuteStoreQuery).
Please let us know if the problem persists.
I m beginner with EF,and my question is is there any way to use one connection string with multiple models.Because my application could have 50 models and it would be funny to change conn string in config 50 times.
Thank you...
No. An EntityConnection provides 2 sets of information: Provider connection string which is basically the database connection string and is equal across all your models (albeit if you are accessing the same database on all of them) and Metadata Information which points to the Conceptual Schema Definition Layer (CSDL), Store Schema Definition Layer (SSDL), and Mapping Schema Layer (MSL) files, and tells the context where to find these files which is NOT equal across your models:
connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;
provider connection string="Data Source=.;...."
The *only* way that you can have one connection string in your solution is to NOT have EDM files at all: **[Entity Framework Code First Development][1]**