Answer the question
In order to leave comments, you need to log in
How to deploy an application via ClickOnce using Entity Framework?
Decided to take a closer look at the world of EF. Since I use MySql for work, I conducted all the experiments on it. For consistency, here is a basic list of required steps that I follow to create a test case:
1. Machine stuffing: Windows 8.1 Pro, VS2013, MySQL Connector 6.8.3, MySQL for VS 1.2 2. Create a C#
3
console application in VS I
add a new element to the project:
4. Select the desired model:
5. Select (or create a new one, if it does not exist) connection:
6. Select the EF 5.0 version (although there are no special options):
7. For simplicity of the experiment, we will select one table:
8. In the appeared App.config file, we will correct the database address (127.0.0.1 -> 192.168.0.37) so that in the end the resulting application can be run on different machines:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DbEntities"
connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=MySql.Data.MySqlClient;provider connection string="server=192.168.0.37;user id=root;password=blablabla;persistsecurityinfo=True;database=testbase""
providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
using System;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
DbEntities context = new DbEntities();
int count = (from a in context.t_abook
select a).Count();
Console.WriteLine("Count records = {0}", count);
}
catch (Exception ex)
{
Console.WriteLine("Exception:\n{0}\n", ex.Message);
if (ex.InnerException != null)
Console.WriteLine("InnerException:\n{0}\n", ex.InnerException.Message);
Console.WriteLine("Stacktrace:\n{0}", ex.StackTrace);
}
finally
{
Console.ReadLine();
}
}
}
}
Answer the question
In order to leave comments, you need to log in
In my project, I did this:
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add
name="MySQL Data Provider"
invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,
Version=6.8.3.0, Culture=neutral,
PublicKeyToken=c5687fc88969c44d"
/>
</DbProviderFactories>
</system.data>
In the project settings Publish -> Prerequisites, checkboxes set the packages that must be installed if they are not available before starting the application. If there is no package you need, then you can create it yourself and add it to the listed list ( msdn.microsoft.com/en-us/library/ms165429.aspx , archive.msdn.microsoft.com/bmg ). This is how I solved the problem with EF Firebird.
And putting a lib in the folder with the program will not work? I think for this it will be enough to set the Copy Local property of the reference to Copy Always.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question