我试图用NH CreateSQLQuery方法获取一些数据
IList<Logistic> LCollection = sess.CreateSQLQuery(@"select * from some_schema.logistic")
.SetResultTransformer(Transformers.AliasToBean(typeof(Logistic)))
.List<Logistic>();
Run Code Online (Sandbox Code Playgroud)
后勤课是
public class Logistic
{
public virtual long? l_id { get; set; }
public virtual long? carrier_id { get; set; }
...
}
Run Code Online (Sandbox Code Playgroud)
制图
public class LogisticMap : ClassMap<Logistic>
{
public LogisticMap()
{
Table("some_chema.logistic");
Id(x => x.l_id).GeneratedBy.Sequence("some_chema.logistic_sq");
Map(x => x.carrier_id);
...
}
}
Run Code Online (Sandbox Code Playgroud)
但我有错误
The type System.Decimal can not be assigned to a property of type System.Nullable`1[System.Int64] setter of MyNamespase.Logistic.l_id
Run Code Online (Sandbox Code Playgroud)
什么可能是错的?
我enum在流畅的NHibernate中映射时遇到了一些问题.我知道这个问题已被多次询问,但我找不到任何对我有用的解决方案.我是NHibernate的新手,看起来我可能错过了一些简单而愚蠢的东西.这是我的代码.
public class DBPublication
{
public virtual int pub_id { get; set; }
public virtual PublicationStatuses status { get; set; }
...
}
public enum PublicationStatuses
{
on_moderation,
active,
...
}
public class DBPublicationMap : ClassMap<DBPublication>
{
public DBPublicationMap()
{
Table("content.publications");
Id(x => x.pub_id).GeneratedBy.Sequence("content.pub_sq");
Map(x => x.status);
...
}
}
Run Code Online (Sandbox Code Playgroud)
postgres枚举类型
CREATE TYPE content.enum_publication_status AS ENUM('on_moderation', 'active', ...);
Run Code Online (Sandbox Code Playgroud)
但是当我试图保存时,postgres会抛出这个
column "status" is of type content.enum_publication_status but expression is of type text
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?
我试图只用这样的代码从我的表中选择一些字段
IList<Product> res = sess.QueryOver<Product>()
.Select(x =>x.name)
.List<Product>();
Run Code Online (Sandbox Code Playgroud)
没有这个代码的错误,但在运行时我得到了这个:"无法执行查找[SQL:SQL不可用]"值"Prod1不是SympleFlhLINQ.Product类型,并且不能在此通用集合上使用".
如果有人告诉我如何只获取产品名称和引用的类别名称宽度,这将是非常好的
IList<Product> res = sess.QueryOver<Product>()
.Select(x =>x.name)
.Select(x=>x.Cat.CategoryName)
.List<Product>();
Run Code Online (Sandbox Code Playgroud)