Insert takes to long

May 14, 2013 at 1:17 PM
Hello, I am using your orm to insert data received from a wcf server. I'm inserting about 10k entities and it takes a longer time then i expected 10min+.
the code is something like this :
foreach (ISentEntity transferEntity in ListTransferEntityes)
{
    MobileEntity mobileObj =  convertFromSentEntityToMobileEntity(transferEntity);
    store.Insert(mobileObj);
}
Are there any settings to the sqlcedatastore i can do to improve performance or another method of insert? I only have one reference made in the entities model and still without using references the speed doesn't improve much.
Coordinator
May 14, 2013 at 2:22 PM
Are you certain it's the Insert that's taking the time? How long does the convertFromSentEntityToMobileEntity call take?
May 28, 2013 at 12:15 PM
After cleaning up my code a bit i found the problem that takes the time. The time consuming part is when I make a select on the database to check for updates(trying to do an update or insert - if object exists update it if not insert it). The duration of the insert when i check for updates is somewhere between 5-10 times more.
Coordinator
May 28, 2013 at 2:28 PM
So the cost is likely in the Reflection work used to build the class and populate its Properties. Did you create your Entity classes manually, or with EntityGenerator? Did you create an ORM Creation Proxy method in the (Entity Generator will do that for you)? It is way faster if you have them.
May 28, 2013 at 2:34 PM
The classes where created manually following one of your examples like this:

entity class:

[Entity(KeyScheme.Identity, NameInStore = "GrupaProduse")]
public class GrupaProduse
{
    [Field(IsPrimaryKey = true, FieldName = "Id")]
    public Int64 id { get; set; }

    [Field(FieldName = "IdFirma")]
    public Int64 idFirma { get; set; }

    [Field(FieldName = "groupID")]
    public string groupID { get; set; }

    [Field(FieldName = "Nume")]
    public string nume { get; set; }

    [Field(FieldName = "IdAgent")]
    public Int64 idAgent { get; set; }
}

SqlCeDataStore class:

m_store = new SqlCeDataStore(Path.Combine(directory_path, "mobileDB.sdf"), "marketing");
        if (!m_store.StoreExists)
        {
            m_store.CreateStore();
        }
        m_store.ConnectionBehavior = ConnectionBehavior.Persistent;
        m_store.UseCommandCache = true;
        m_store.AddType<GrupaProduse>();
        m_store.EnsureCompatibility();

And so on for all the entities. If u can give an example on what to change to improve the select performance I would much appreciate it.
May 29, 2013 at 2:57 PM
Also found another problem. I can't insert a datetime value in the db except for the default one(DefaultType = DefaultType.CurrentDateTime). If i change it to another field and do an interogation again it changes back to currentdatetime. If i don't set a default type it is set to 01/01/01
Coordinator
May 29, 2013 at 3:55 PM
What store type is this against? What platform?
May 29, 2013 at 4:38 PM
I updated my version to the latest one but i still can't insert DateTime in a SQLCE. I tried to set DataType=Dbtype.DateTime i tried withoud datatype or defaulttype and I still can't insert

[Field(FieldName = "Data")]
public DateTime dataRouting { get; set; }

or

[Field(FieldName = "Data", DefaultType = DefaultType.None)]
public DateTime dataRouting { get; set; }

or

[Field(FieldName = "Data", DataType=DbType.DateTime)]
public DateTime dataRouting { get; set; }

the date is set to 01/01/01 when i try to modify

when i set:

[Field(FieldName = "Data", DefaultType = DefaultType.CurrentDateTime)]
    public DateTime dataRouting { get; set; }
the date is set to current date when i try to modify
the initial object changes its datetime but when i do another select the date is reseted to the default
Coordinator
May 29, 2013 at 5:02 PM
I need some help with reproducing the DateTime issue. I just verified that this works:
[TestMethod()]
public void DateTimeTest()
{
    m_store.TruncateTable("TestItem");

    var itemA = new TestItem("ItemA");
    m_store.Insert(itemA);

    var checkItem = m_store.Select<TestItem>().FirstOrDefault();
    Assert.AreEqual(itemA.TestDate, checkItem.TestDate);

    var now = DateTime.Now;

    itemA.TestDate = now;

    m_store.Update(itemA);
    checkItem = m_store.Select<TestItem>().FirstOrDefault();
    Assert.AreEqual(itemA.TestDate.Second, checkItem.TestDate.Second);
}
Coordinator
May 29, 2013 at 5:19 PM
For your object creation speed issue, see the (new) documentation page here: https://orm.codeplex.com/wikipage?title=ORM_CreateProxy
May 29, 2013 at 5:33 PM
Ok it seems my version didn't update so i check again and update it so everything works fine now. Sorry I disturbed you:P.