KitchenPC和Ironpython [英] KitchenPC and Ironpython
问题描述
我正在使用Database Provisioning示例: http://blog.kitchenpc.com/2014/02/11/kitchenpc-database-provisioning-101/ a>
我正在成功引用和导入所有的dll及其名称空间:
import clr
从System.Reflection导入* b $ b从System.Reflection导入*
导入程序集中的clr.AddReference(系统)
导入程序集
$ b $ L4N = Assembly.LoadFrom('C://KitchenPC//DLL//log4net.dll')
clr.AddReference(L4N)
NU = Assembly.LoadFrom('C://KitchenPC//DLL//nunit.framework.dll')
clr.AddReference(NU)
LC = Assembly.LoadFrom('C:/ /KitchenPC//DLL//Iesi.Collections.dll')
clr.AddReference(LC)
PGSQL = Assembly.LoadFrom('C:// KitchenPC // DLL // Npgsql .dll')
clr.A ddReference(PGSQL)
NH = Assembly.LoadFrom('C://KitchenPC//DLL//NHibernate.dll')
clr.AddReference(NH)
FNH = Assembly.LoadFrom('C://KitchenPC//DLL//FluentNHibernate.dll')
clr.AddReference(FNH)
KPC = Assembly.LoadFrom('C :// KitchenPC//DLL//KitchenPC.dll')
clr.AddReference(KPC)
KPCDB = Assembly.LoadFrom('C:// KitchenPC // DLL // KitchenPC .DB.dll')
clr.AddReference(KPCDB)
clr.AddReferenceToFileAndPath('C://KitchenPC//DLL//FluentNHibernate.dll')
从Npgsql导入*
从log4net导入*
从Iesi.Collections导入*
$ b从FluentNHibernate导入* b $ b从FluentNHibernate.Cfg导入*
从FluentNHibernate.Cfg.Db导入*
从NHibernate导入*
从NHibernate.Cfg导入配置
$ b从KitchenPC导入* b $ b从KitchenPC.DB从KitchenPC.Context导入*
从KitchenPC.DB导入DBContext
导入DatabaseAdapter
from NUnit.Framework import *
我可以定义一个就像这样:
$ $ $ $ $ codeonnString =Server = localhost; Port = 5432; User Id = postgres; Password = password; Database = KPCSample
#上下文连接到本地数据库
DBC = PostgreSQLConfiguration.PostgreSQL82.ConnectionString(connString).ShowSql()
但是当我尝试设置databaseAdapter时:
DatabaseAdapter.Configure.DatabaseConfiguration(DBC)
我遇到了错误:
$ p $
TypeError:预期的IPersistenceConfigurer,得到PostgreSQLConfiguration
奇怪的是实例( DBC
, IPersistenceConfigurer
)返回 True
,因此DBC确实是抽象类 IPersistenceConfigurer
的一个实例,它是 DatabaseAdapte的子类r
。
以下是我尝试从C#转置的原始代码的示例:
//上下文连接到本地数据库
var dbConfig = Configuration.Build
.Context(DBContext.Configure
.Adapter(DatabaseAdapter。配置
.DatabaseConfiguration(
PostgreSQLConfiguration.PostgreSQL82
.ConnectionString(@Server = localhost; Port = 5432; User Id = Website; Password = password; Database = KPCSample)
.ShowSql()
)
)
).Create();
//上下文连接到本地数据存储
var staticConfig = Configuration.Build
.Context(StaticContext.Configure
.DataDirectory(@C:\KitchenPC \ConsoleTest\LocalStore\)
)
.Create();
以下是 DatabaseAdapter
类的示例来自KitchenPC:
///< summary>一个使用NHibernate连接底层数据库的数据库适配器<总结>
?
public class DatabaseAdapter:IDBAdapter,IDisposable
{
ISessionFactory sessionFactory;
配置nhConfig;
只读DatabaseAdapterBuilder构建器;
public IPersistenceConfigurer DatabaseConfiguration {get;组; }
public List< IConvention> DatabaseConventions {get;组; }
public ISearchProvider SearchProvider {get;组; }
public static DatabaseAdapterBuilder配置
{
get
{
return new DatabaseAdapter()。builder;
DatabaseAdapter()
{
builder = new DatabaseAdapterBuilder(this);
$ b我在做什么错误实例<$ c $在Ironpython中的DatabaseAdapter
解决方案结果,我导入的方式是
基本上,导入应该是这样的:
pre $ code $> import clr
import sys
sys.path.append(os.path.abspath('./ DLL'))#你的dll是
clr.AddReference('System')
clr.AddReference('FluentNHibernate')
from FluentNHibernate.Cfg.Db import PostgreSQLConfiguration
如果另一个DLL将其导入到clr中,则不需要导入DLL。
I am attempting to work with KitchenPC using IronPython.
I am working with the Database Provisioning example here: http://blog.kitchenpc.com/2014/02/11/kitchenpc-database-provisioning-101/
I am successfully referencing and importing all the dlls and their namespaces:
import clr
clr.AddReference("System")
from System import *
from System.Reflection import *
from System.Reflection import Assembly
L4N = Assembly.LoadFrom('C://KitchenPC//DLL//log4net.dll')
clr.AddReference(L4N)
NU= Assembly.LoadFrom('C://KitchenPC//DLL//nunit.framework.dll')
clr.AddReference(NU)
LC= Assembly.LoadFrom('C://KitchenPC//DLL//Iesi.Collections.dll')
clr.AddReference(LC)
PGSQL = Assembly.LoadFrom('C://KitchenPC//DLL//Npgsql.dll')
clr.AddReference(PGSQL)
NH = Assembly.LoadFrom('C://KitchenPC//DLL//NHibernate.dll')
clr.AddReference(NH)
FNH = Assembly.LoadFrom('C://KitchenPC//DLL//FluentNHibernate.dll')
clr.AddReference(FNH)
KPC = Assembly.LoadFrom('C://KitchenPC//DLL//KitchenPC.dll')
clr.AddReference(KPC)
KPCDB = Assembly.LoadFrom('C://KitchenPC//DLL//KitchenPC.DB.dll')
clr.AddReference(KPCDB)
clr.AddReferenceToFileAndPath('C://KitchenPC//DLL//FluentNHibernate.dll')
from Npgsql import *
from log4net import *
from Iesi.Collections import *
from FluentNHibernate import *
from FluentNHibernate.Cfg import *
from FluentNHibernate.Cfg.Db import *
from NHibernate import *
from NHibernate.Cfg import Configuration
from KitchenPC import *
from KitchenPC.DB import *
from KitchenPC.Context import DBContext
from KitchenPC.DB import DatabaseAdapter
from NUnit.Framework import *
I can define a PostgreSQLConfiguration
like so:
connString = "Server=localhost;Port=5432;User Id=postgres;Password=password;Database=KPCSample"
# Context connected to local database
DBC = PostgreSQLConfiguration.PostgreSQL82.ConnectionString(connString).ShowSql()
But when I try to setup the databaseAdapter:
DatabaseAdapter.Configure.DatabaseConfiguration( DBC )
I am running into an error:
TypeError: expected IPersistenceConfigurer, got PostgreSQLConfiguration
The strange thing is that is instance(DBC
, IPersistenceConfigurer
) returns True
, so DBC is indeed an instance of the the abstract class IPersistenceConfigurer
which is a subclass of DatabaseAdapter
.
Here is a sample of the original code I am attempting to transpose from C#:
// Context connected to local database
var dbConfig = Configuration.Build
.Context(DBContext.Configure
.Adapter(DatabaseAdapter.Configure
.DatabaseConfiguration(
PostgreSQLConfiguration.PostgreSQL82
.ConnectionString(@"Server=localhost;Port=5432;User Id=Website;Password=password;Database=KPCSample")
.ShowSql()
)
)
).Create();
// Context connected to local data store
var staticConfig = Configuration.Build
.Context(StaticContext.Configure
.DataDirectory(@"C:\KitchenPC\ConsoleTest\LocalStore\")
)
.Create();
Here is a sample of the DatabaseAdapter
class from KitchenPC:
/// <summary>A database adapter that uses NHibernate to connect to an underlying database.</summary>
public class DatabaseAdapter : IDBAdapter, IDisposable
{
ISessionFactory sessionFactory;
Configuration nhConfig;
readonly DatabaseAdapterBuilder builder;
public IPersistenceConfigurer DatabaseConfiguration { get; set; }
public List<IConvention> DatabaseConventions { get; set; }
public ISearchProvider SearchProvider { get; set; }
public static DatabaseAdapterBuilder Configure
{
get
{
return new DatabaseAdapter().builder;
}
}
DatabaseAdapter()
{
builder = new DatabaseAdapterBuilder(this);
}
}
What am I doing wrong with instantiating DatabaseAdapter
in Ironpython?
So it turns out, that the way I was importing was incorrect.
But basically, imports should be like so:
import clr
import sys
sys.path.append(os.path.abspath('./DLL')) #where your dlls are
clr.AddReference('System')
clr.AddReference('FluentNHibernate')
from FluentNHibernate.Cfg.Db import PostgreSQLConfiguration
There is no need to import a DLL if another DLL imports it in the clr.
这篇关于KitchenPC和Ironpython的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!