The original program used SQLite this embedded database as the remit (code name) data source, because nhibernate support this, but a little bad is that SQLite does not support foreign keys, resulting in sad codesmith can not be a relationship, I can't generate a many-to-many map that I like. If handwriting is going to write mapping XML files and business entity classes, this is what I lazy people do not like. Moreover, the database changes frequently, good code generation can do database and code synchronization.
The hard drive is broken. It's also an opportunity, and it occurred to me that SQL Server also has a CE version that now offers more than for mobile and desktop editions. This lovely embedded database is much better than boring access. Although this thing does not have store produce (in fact, there is no need to use ORM), but the index Ah, the table relationship is still very comprehensive. Microsoft's things are good for the benefit of all lazy people.
However, my database turned out to be access, and found a half-day tool on the Internet to find only one SQL to SQL CE tool. You then use the Upsizing Wizard for access to move to MS SQL and then create a table relationship in MS SQL Server. Then use that tool to import into the Sql CE. Then I compiled a codesmith database schema provider (because this was for 4.0, and Mine was 5.0).
The migration tool seems to be a bit of a problem, with no complete copy of the table relationship, your own SQL Menagement studio version may be too low, Unable to open the 3.5 CE database. The result is that you can't generate the relationship I want with codesmith. Think of NHibernate in fact, for the table relationship is not dependent on the database, as long as there is a table on it, so think of a special two method, is to use MS SQL to do codesmith data sources, generate files, and the program uses the migrated CE database. (In fact, the feeling of direct use of MS SQL Server can also, the final release of the time to change CE)
The most depressing thing, though, was that when I was testing using NHibernate, I was prompted that a query could not be executed, and that query in the VS 2008 database query was a select This_.id as id2_0_, This_. BookName as bookname2_0_, This_. LangID as langid2_0_ from dbo. Book This_ I am really helpless ah, looking for the wrong nhibernate thrown out of the abnormal innerexception also see what to do, I used ADO to write a
System.Data.SqlServerCe.SqlCeConnection conn=new System.Data.SqlServerCe.SqlCeConnection(@"Data Source=E:\Loning\Loning.Remit\db.sdf");
SqlCeCommand command=new SqlCeCommand("SELECT this_.ID as ID2_0_, this_.BookName as BookName2_0_, this_.LangID as LangID2_0_ FROM dbo.Book this_",conn);
conn.Open();
The last thing that prompted the table name exception, I checked the table name, remember because it was generated by SQL Server, with a dbo. Prefix, found the generated nhibernate configuration file
<?xml version= "1.0" encoding= "Utf-8"
<class name=" Loning.Remit.BusinessObjects.Book, Loning.remit "table=" dbo. Book "lazy=" true "
<id name=" id "column=" id "
<generator class=" Assigned "/> </id>
<property name= "BookName" column= "BookName"/>
<many-to-one name= " Language "column=" LangID class= "Language"/>
<bag name= "Words" lazy= "true" cascade= "All" inverse= "true"
<key column= "BookID" ></KEY>
<one-to-many class= "Word" ></one-to- Many>
</bag>
</class>
Where the dbo is present, it is normal to remove it, and then change the Codesmith template. Change the table.fullname to Table.name, build the correct configuration file, and then regenerate, compile. It's over. I began to toss from 5 o'clock in the afternoon, has been tossing to 11 points, finally solved these problems, I hope ce this thing can work well ...