working with two databases

Oct 25, 2007 at 9:51 AM
Hi,

I use 2 databases, the first use default appConfig configuration (Sqlite in local)
and the second use (Mysql on network) like your sample

"DbContext ds = new DbContext(EntryConfig.GetDriver("MySql"));

if I use
"ds.ExecuteDataset ("INSERT INTO `documents` VALUES ("test","test");"
the data is save in the database (Mysql))

but if I use
"Document doc = Document.New("test", "test");"
ds.Save(doc);"

the data is not saved
I don't understand how is the good code

"ds.Insert(doc);" and "doc.Save();" don't work also


thanks
Oct 25, 2007 at 4:36 PM
hello, i made several tests

my class "user" who has only one "HasOne" relation, function very well,
but the Document class who has several "HasOne" relations and one "HasMany" relation don't work.
the save code is :
"ds.Save(doc);"

thanks
Coordinator
Oct 26, 2007 at 1:44 AM
I test it and can't reproduce the situation you mentioned.

My app.config is:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="Lephone.Settings" type="Lephone.Util.Setting.NameValueSectionHandler, Lephone.Util" />
  </configSections>
 
  <Lephone.Settings>
    <add key="DataBase" value="@SQLite : @~Test.db" />
    <add key="DbProviderFactory" value="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.36.1, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
 
    <add key="MySql.DataBase" value="@MySql : server=localhost; user id=root; password=123; database=mytest; pooling=false" />
    <add key="MySql.DbProviderFactory" value="@SmartDbFactory : MySql.Data, Version=5.1.2.2, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  </Lephone.Settings>
</configuration>

My test code is:
 
using System;
using System.Collections.Generic;
using Lephone.Data;
using Lephone.Data.Definition;
 
public abstract class User : DbObjectModel<User>
{
    [BelongsTo]
    public abstract Books Name { get; set; }
}
 
public abstract class MyTime : DbObjectModel<MyTime>
{
    [BelongsTo]
    public abstract Books Name { get; set; }
}
 
public abstract class Next : DbObjectModel<Next>
{
    [BelongsTo]
    public abstract Books Name { get; set; }
}
 
public abstract class Books : DbObjectModel<Books>
{
    public abstract string title { get; set; }
    public abstract string description { get; set; }
    public abstract DateTime buydate { get; set; }
 
    [HasOne]
    public abstract User nuser { get; set; }
 
    [HasOne]
    public abstract MyTime mtime { get; set; }
 
    [HasMany]
    public abstract IList<Next> xyz { get; set; }
 
    public Books()
    {
    }
 
    public Books(string title, string description, DateTime buydate)
    {
        this.title = title;
        this.description = description;
        this.buydate = buydate;
    }
}
 
class Program
{
    static void Main(string[] args)
    {
        DbContext db = new DbContext("MySql");
        Books b = Books.New("tom", "cat", DateTime.Now);
        db.Save(b);
        Console.WriteLine(b);
        Console.ReadLine();
    }
}
There is little thing I want mentioned is when we define "HasMany" "HasAndBelongsToMany" fields with abstract property, the type of it should be "IList<T>", not "List<T>".

If you still have this issue, please make it as a small program to let me can reproduce it.
Oct 26, 2007 at 6:52 AM
I tested from your example
it was my code which was not good
I had forgotten a not null field which remained at null

I apologize to you have disturbed for nothing

thank you still