I follow your suggestion and workaround, but because my model have a lot association, I delete all association, and its working, I can delete and create database without problem,
because of that, I must have association function that I create by my self, without association attribute from LinqConnect
If my understanding does not wrong, assosiaction in my model, included at sql table creation query, at database level
1. How to exclude this association from sql generation? I just want association at class data level, not database level, because,I dont want constraint or foreign key on database/table creation query, I use MySQL and SQLServer, one or another
2. How to change diagram connection or sql script generation for specific database provider? the original one is SQL Server like my diagram, I want to change it to MySQL
3. Can I create or delete at runtime for one specific table?
4. On database context class, have database attribute for database name, what different with connection string database name? ("database" on mysql or "Initial Catalog" for SQL Server), which one is most significant priority?
5. How I can define update behavior for associated table?, ex. I can define just for read associated table, if master table updated, associated table does not update (just like join select from several table), or if master table is updated, then associated table updated too
6. I recreated all my association, sample project attached, and I use MySQL data provider, instead SQL Server, with little edit on database context, I have 2 database context file, one for MySQL and another for SQL Server, I just exclude or include one of them, but for MySQL, and for MemberData class that have association for itself, parent child association, exception raised
Code: Select all
Devart.Data.Linq.LinqCommandExecutionException was unhandled
HResult=-2146233088
Message=Error on executing DbCommand.
Source=Devart.Data.Linq
StackTrace:
at Devart.Data.Linq.LinqCommandExecutionException.CanThrowLinqCommandExecutionException(String message, Exception e)
at Devart.Data.Linq.DataProvider.CommandExecuter.Execute(String sql)
at Devart.Data.Linq.DataProvider.CommandExecuter.Execute(List`1 sqls)
at Devart.Data.Linq.DataProvider.CreateDatabase(Boolean ignoreErrors, Boolean createSchema)
at Devart.Data.Linq.DataProvider.b(Boolean A_0, Boolean A_1)
at Devart.Data.Linq.DataContext.CreateDatabase(Boolean ignoreErrors, Boolean createSchema)
at eCoMaxDBData3.Program.Main(String[] args) in F:\My Document\Visual Studio 2010\Projects\eCoMaxDotNetSQLServer\eCoMaxDBData3\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: Devart.Data.MySql.MySqlException
HResult=-2147467259
Message=Can't create table '.\ecomax2\member.frm' (errno: 150)
Source=Devart.Data.MySql
ErrorCode=-2147467259
Code=1005
SqlState=HY000
StackTrace:
at Devart.Data.MySql.MySqlCommand.InternalExecute(CommandBehavior behavior, IDisposable stmt, Int32 startRecord, Int32 maxRecords)
at Devart.Common.DbCommandBase.InternalExecute(CommandBehavior behavior, IDisposable stmt, Int32 startRecord, Int32 maxRecords, Boolean nonQuery)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior)
at Devart.Common.DbCommandBase.ExecuteNonQuery()
at Devart.Data.Linq.DataProvider.CommandExecuter.Execute(String sql)
InnerException:
if I execute my console program for SQL Server I have this exception
Code: Select all
Devart.Data.Linq.LinqCommandExecutionException was unhandled
HResult=-2146233088
Message=Error on executing DbCommand.
Source=Devart.Data.Linq
StackTrace:
at Devart.Data.Linq.LinqCommandExecutionException.CanThrowLinqCommandExecutionException(String message, Exception e)
at Devart.Data.Linq.DataProvider.CommandExecuter.Execute(String sql)
at Devart.Data.Linq.DataProvider.CommandExecuter.Execute(List`1 sqls)
at Devart.Data.Linq.DataProvider.CreateDatabase(Boolean ignoreErrors, Boolean createSchema)
at Devart.Data.Linq.DataProvider.b(Boolean A_0, Boolean A_1)
at Devart.Data.Linq.DataContext.CreateDatabase(Boolean ignoreErrors, Boolean createSchema)
at eCoMaxDBData3.Program.Main(String[] args) in F:\My Document\Visual Studio 2010\Projects\eCoMaxDotNetSQLServer\eCoMaxDBData3\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Data.SqlClient.SqlException
HResult=-2146232060
Message=There are no primary or candidate keys in the referenced table 'member' that match the referencing column list in the foreign key 'FK_member_member_0'.
Could not create constraint. See previous errors.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=1776
Procedure=""
Server=127.0.0.1
State=0
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Devart.Data.Linq.DataProvider.CommandExecuter.Execute(String sql)
InnerException:
it says that no primary or candidate key, but on my model two field that I associated already entity key
and this my sample project, please use exclude or include project to switch between data sql server datacontext or mysql datacontext from SolutionExplorer
https://www.dropbox.com/s/bg21rztx8wc9t ... BData3.zip