所以,我遇到了FluentNHibernate的问题。我已经映射了所有属性,我已经链接了我的表,我收到了一个错误:
使用无效或不完整的配置创建SessionFactory。检查PotentialReasons集合,以及InnerException以获取更多详细信息。
不确定是什么问题,因为我根据以前的程序创建了映射,类和数据库。我创建SessionFactory的DataLayer类是:
namespace WTF.Edit1
{
public class DataLayer
{
private static ISessionFactory _factory = null;
private static object objLock = new object();
public static ISession GetSession()
{
if (_factory == null)
{
lock (objLock)
{
if (_factory == null)
_factory = CreateSessionFactory();
}
}
return _factory.OpenSession();
}
//konfiguracija i kreiranje session factory
private static ISessionFactory CreateSessionFactory()
{
try
{
var cfg = OracleManagedDataClientConfiguration.Oracle10
.ConnectionString(c =>
c.Is("Data Source=datasource:1111/AAAA;User Id=user;Password=pass"));
return Fluently.Configure()
.Database(cfg)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<KorisnikMapiranja>())
.BuildSessionFactory();
}
catch (Exception ec)
{
System.Windows.Forms.MessageBox.Show(ec.Message);
return null;
}
}
}
}
我想将信息放在数据库中的特定类是:
namespace WTF.Edit1.Podaci
{
public class Korisnik
{
public virtual string Tip { get; set; }
public virtual string Ime { get; set; }
public virtual string Prezime { get; set; }
public virtual string KorisnickoIme { get; set; }
public virtual string Lozinka { get; set; }
public virtual string PonovljenaLozinka { get; set; }
public virtual string Email { get; set; }
public virtual string Pol { get; set; }
public virtual IList<Recept> Recepti { get; set; }
public virtual IList<Komentar> Komentari { get; set; }
public virtual IList<Ocena> Ocene { get; set; }
public Korisnik()
{
Recepti = new List<Recept>();
Komentari = new List<Komentar>();
Ocene = new List<Ocena>();
}
}
public class User : Korisnik
{
}
public class Admin : Korisnik
{
}
}
映射是:
namespace WTF.Edit1.Mapiranja
{
class KorisnikMapiranja : ClassMap<Korisnik>
{
public KorisnikMapiranja()
{
Table("KORISNIK");
Id(x => x.KorisnickoIme, "USERNAME");
Map(x => x.Ime, "IME");
Map(x => x.Prezime, "PREZIME");
Map(x => x.Email, "EMAIL");
Map(x => x.Lozinka, "PASSWORD");
Map(x => x.PonovljenaLozinka, "PASSREPEAT");
Map(x => x.Pol, "POL");
Map(x => x.Tip, "TIP");
HasMany(x => x.Recepti).KeyColumn("USERNAME");
HasMany(x => x.Komentari).KeyColumn("USERNAME");
HasMany(x => x.Ocene).KeyColumn("USERNAME");
}
}
class UserMapiranja : SubclassMap<User>
{
public UserMapiranja()
{
Table("USERI");
KeyColumn("USERNAME");
}
}
class AdminMapiranja : SubclassMap<Admin>
{
public AdminMapiranja()
{
Table("ADMIN");
KeyColumn("USERNAME");
}
}
}
有什么想法吗?我试图研究并找到答案,但没有任何对我有用。
答案 0 :(得分:0)
您可能缺少Oracle托管客户端。 您需要将其引用/可访问才能使用 OracleManagedDataClientConfiguration 。
如果可能,只需通过nuget安装相应的软件包,看看是否是导致异常的原因: https://www.nuget.org/packages/Oracle.ManagedDataAccess/
安装包 - Oracle.ManagedDataAccess