Y
Y
Ytsu Ytsuevich2015-10-29 21:27:21
C++ / C#
Ytsu Ytsuevich, 2015-10-29 21:27:21

How to put Entity in a separate project?

When you add the ADO.NET Entity Data Model , Entity objects are created. A connection string is added to the config (and not only).
If I create a separate project and add Entity to it, then everything works there if I run that project.
If you just refer to it, then various errors occur. Connection string added!
The question is how do you do it?
Here are the errors:
1) Need connectionString
1b4e1ea08b7c4b0592de14892266a674.PNG
Added
d7b2c11d504b46ab9d5f91632194c6aa.PNG
2) Need a provider
cce2e115d7364ca6a1d2b3b2d56d8d43.PNG
Added
c17265d7c08b41eb8f71e94f5e22fe27.PNG
3) It's not clear what you need
40379bd1885c4289b50e07aa01e589e4.PNG
So what to add?
Maybe I added something wrong above? I just took it from the config in the project where the Entity is and inserted it into the config of the called project.
Isn't it necessary?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Ytsu Ytsuevich, 2015-10-31
@kofon

Added, there is an answer!
Here are the internal exceptions:
1)
2)
The following null
==========
Answer:

Evolving, through trial and error ( I found it that way ), and searching for the right answer on the English-language forums, I managed to separate Entity into a separate project.
So:
First project with Entity along with .edmx model (type - library).
The second project to run (type - web or console).
1) In the project being launched, in addition to the link to the first one, add links to EntityFramework and EntityFramework.%Provider% (in my case, EntityFramework.SqlServer), even though these links were added in the first draft.
2) You need to add a field with <connectionStrings> to the config file , and there's nothing else! Don't add a block with entityFramework ! It's all. Who helped, unsubscribe ...

D
Dmitry Kovalsky, 2015-10-29
@dmitryKovalskiy

Create a project where you will store connectionString sets. Create a project in which there will be an Entity and put a link to the strings in another project. Create an Entity without adding entries to the configs (there is a corresponding checkbox), but saving the database metadata somewhere. Next, next to the Entity file, add an extension through partial to the context class. In it, you need a Get method without parameters, inside it you create an EntityConnectionStringBuilder, into which you will slip the necessary connection to the database from the project with connections, and the metadata saved in advance. The Get method must return a context object, via your constructor.
More or less like this

partial class MyContext{
public static MyContext Get()
{
var t = new EntityConnectionStringBuilder();
return new MyContext(t)
}
public MyContext(EntityConnectionStringBuilder ecsb):base(ecsb)
{

}

}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question