我正试图将现有数据库映射到Nhibernate中,但当我执行查询时,我收到以下错误:
InnerException={无法识别的Guid格式。}
消息=";无法执行查询[SELECT*FROM carte WHERE custom_id=?p0]\r\n名称:custom_id值:111[SQL:SELECT*FROM carte WHERE customer_id=?p0]">
我找不到错误,有人能帮我吗?
信息:该项目是一个基于.net内核3.1的wpf。Nhibernate 5.3.0MySql.Data 8.0.21
Db:Mysql(如果我使用"sandard"sql连接,一切正常(
这是我的地图hbm文件:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="CenturionCommanderTools" namespace="CenturionCommanderTools.Database.Models" xmlns="urn:nhibernate-mapping-2.2">
<class name="Carte" table="carte" lazy="false" >
<id name="custom_id" column="custom_id" type="UInt64">
<generator class="native" />
</id>
<property name="arena_id">
<column name="arena_id" sql-type="int(11)" not-null="false" />
</property>
<property name="id">
<column name="id" sql-type="char(36)" not-null="false" />
</property>
<property name="language">
<column name="language" sql-type="varchar(255)" not-null="false" />
</property>
<property name="mtgo_id">
<column name="mtgo_id" sql-type="int(11)" not-null="false" />
</property>
<property name="mtgo_foil_id">
<column name="mtgo_foil_id" sql-type="int(11)" not-null="false" />
</property>
<property name="multiverse_ids">
<column name="multiverse_ids" sql-type="text" not-null="false" />
</property>
<property name="tcgplayer_id">
<column name="tcgplayer_id" sql-type="int(11)" not-null="false" />
</property>
<property name="card_object">
<column name="object" sql-type="varchar(255)" not-null="false" />
</property>
<property name="oracle_id">
<column name="oracle_id" sql-type="char(36)" not-null="false" />
</property>
<property name="prints_search_uri">
<column name="prints_search_uri" sql-type="text" not-null="false" />
</property>
<property name="rulings_uri">
<column name="rulings_uri" sql-type="text" not-null="false" />
</property>
<property name="scryfall_uri">
<column name="scryfall_uri" sql-type="text" not-null="false" />
</property>
<property name="uri_cdb">
<column name="uri" sql-type="text" not-null="false" />
</property>
<property name="all_parts">
<column name="all_parts" sql-type="text" not-null="false" />
</property>
<property name="card_faces">
<column name="card_faces" sql-type="text" not-null="false" />
</property>
<property name="cmc">
<column name="cmc" sql-type="float" not-null="false" />
</property>
<property name="colors">
<column name="colors" sql-type="text" not-null="false" />
</property>
<property name="color_identity">
<column name="color_identity" sql-type="text" not-null="false" />
</property>
<property name="color_indicator">
<column name="color_indicator" sql-type="text" not-null="false" />
</property>
<property name="edhrec_rank">
<column name="edhrec_rank" sql-type="int(11)" not-null="false" />
</property>
<property name="foil">
<column name="foil" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="hand_modifier">
<column name="hand_modifier" sql-type="varchar(255)" not-null="false" />
</property>
<property name="layout">
<column name="layout" sql-type="varchar(255)" not-null="false" />
</property>
<property name="legalities">
<column name="legalities" sql-type="text" not-null="false" />
</property>
<property name="life_modifier">
<column name="life_modifier" sql-type="varchar(255)" not-null="false" />
</property>
<property name="loyalty">
<column name="loyalty" sql-type="varchar(255)" not-null="false" />
</property>
<property name="mana_cost">
<column name="mana_cost" sql-type="varchar(255)" not-null="false" />
</property>
<property name="name_card">
<column name="name" sql-type="varchar(255)" not-null="false" />
</property>
<property name="nonfoil">
<column name="nonfoil" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="oracle_text">
<column name="oracle_text" sql-type="text" not-null="false" />
</property>
<property name="oversized">
<column name="oversized" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="power">
<column name="power" sql-type="varchar(255)" not-null="false" />
</property>
<property name="reserved">
<column name="reserved" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="toughness">
<column name="toughness" sql-type="varchar(255)" not-null="false" />
</property>
<property name="type_line">
<column name="type_line" sql-type="varchar(255)" not-null="false" />
</property>
<property name="artist">
<column name="artist" sql-type="varchar(255)" not-null="false" />
</property>
<property name="booster">
<column name="booster" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="border_color">
<column name="border_color" sql-type="varchar(255)" not-null="false" />
</property>
<property name="card_back_id">
<column name="card_back_id" sql-type="char(36)" not-null="false" />
</property>
<property name="collector_number">
<column name="collector_number" sql-type="varchar(255)" not-null="false" />
</property>
<property name="digital">
<column name="digital" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="flavor_text">
<column name="flavor_text" sql-type="text" not-null="false" />
</property>
<property name="frame_effect">
<column name="frame_effect" sql-type="varchar(255)" not-null="false" />
</property>
<property name="frame">
<column name="frame" sql-type="varchar(255)" not-null="false" />
</property>
<property name="full_art">
<column name="full_art" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="games">
<column name="games" sql-type="text" not-null="false" />
</property>
<property name="highres_image">
<column name="highres_image" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="illustration_id">
<column name="illustration_id" sql-type="char(36)" not-null="false" />
</property>
<property name="image_uris">
<column name="image_uris" sql-type="text" not-null="false" />
</property>
<property name="prices">
<column name="prices" sql-type="text" not-null="false" />
</property>
<property name="printed_name">
<column name="printed_name" sql-type="varchar(255)" not-null="false" />
</property>
<property name="printed_text">
<column name="printed_text" sql-type="text" not-null="false" />
</property>
<property name="printed_type_line">
<column name="printed_type_line" sql-type="varchar(255)" not-null="false" />
</property>
<property name="promo">
<column name="promo" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="promo_types">
<column name="promo_types" sql-type="text" not-null="false" />
</property>
<property name="purchase_uris">
<column name="purchase_uris" sql-type="text" not-null="false" />
</property>
<property name="rarity">
<column name="rarity" sql-type="varchar(255)" not-null="false" />
</property>
<property name="related_uris">
<column name="related_uris" sql-type="text" not-null="false" />
</property>
<property name="released_at">
<column name="released_at" sql-type="date" not-null="false" />
</property>
<property name="reprint">
<column name="reprint" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="scryfall_set_uri">
<column name="scryfall_set_uri" sql-type="text" not-null="false" />
</property>
<property name="set_name">
<column name="set_name" sql-type="varchar(255)" not-null="false" />
</property>
<property name="set_search_uri">
<column name="set_search_uri" sql-type="text" not-null="false" />
</property>
<property name="set_type">
<column name="set_type" sql-type="varchar(255)" not-null="false" />
</property>
<property name="set_uri">
<column name="set_uri" sql-type="text" not-null="false" />
</property>
<property name="set">
<column name="set" sql-type="varchar(255)" not-null="false" />
</property>
<property name="story_spotlight">
<column name="story_spotlight" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="textless">
<column name="textless" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="variation">
<column name="variation" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="variation_of">
<column name="variation_of" sql-type="char(36)" not-null="false" />
</property>
<property name="watermark">
<column name="watermark" sql-type="varchar(255)" not-null="false" />
</property>
<property name="created_at">
<column name="created_at" sql-type="timestamp" not-null="false" />
</property>
<property name="updated_at">
<column name="updated_at" sql-type="timestamp" not-null="false" />
</property>
</class>
</hibernate-mapping>
地图类别:
using System;
using System.Text;
using System.Collections.Generic;
namespace CenturionCommanderTools.Database.Models {
[Serializable]
public class Carte {
public virtual UInt64 custom_id { get; set; }
public virtual int? arena_id { get; set; }
public virtual string id { get; set; }
public virtual string language { get; set; }
public virtual int? mtgo_id { get; set; }
public virtual int? mtgo_foil_id { get; set; }
public virtual string multiverse_ids { get; set; }
public virtual int? tcgplayer_id { get; set; }
public virtual string card_object { get; set; }
public virtual string oracle_id { get; set; }
public virtual string prints_search_uri { get; set; }
public virtual string rulings_uri { get; set; }
public virtual string scryfall_uri { get; set; }
public virtual string uri_cdb { get; set; }
public virtual string all_parts { get; set; }
public virtual string card_faces { get; set; }
public virtual float? cmc { get; set; }
public virtual string colors { get; set; }
public virtual string color_identity { get; set; }
public virtual string color_indicator { get; set; }
public virtual int? edhrec_rank { get; set; }
public virtual int? foil { get; set; }
public virtual string hand_modifier { get; set; }
public virtual string layout { get; set; }
public virtual string legalities { get; set; }
public virtual string life_modifier { get; set; }
public virtual string loyalty { get; set; }
public virtual string mana_cost { get; set; }
public virtual string name_card { get; set; }
public virtual int? nonfoil { get; set; }
public virtual string oracle_text { get; set; }
public virtual int? oversized { get; set; }
public virtual string power { get; set; }
public virtual int? reserved { get; set; }
public virtual string toughness { get; set; }
public virtual string type_line { get; set; }
public virtual string artist { get; set; }
public virtual int? booster { get; set; }
public virtual string border_color { get; set; }
public virtual string card_back_id { get; set; }
public virtual string collector_number { get; set; }
public virtual int? digital { get; set; }
public virtual string flavor_text { get; set; }
public virtual string frame_effect { get; set; }
public virtual string frame { get; set; }
public virtual int? full_art { get; set; }
public virtual string games { get; set; }
public virtual int? highres_image { get; set; }
public virtual string illustration_id { get; set; }
public virtual string image_uris { get; set; }
public virtual string prices { get; set; }
public virtual string printed_name { get; set; }
public virtual string printed_text { get; set; }
public virtual string printed_type_line { get; set; }
public virtual int? promo { get; set; }
public virtual string promo_types { get; set; }
public virtual string purchase_uris { get; set; }
public virtual string rarity { get; set; }
public virtual string related_uris { get; set; }
public virtual DateTime? released_at { get; set; }
public virtual int? reprint { get; set; }
public virtual string scryfall_set_uri { get; set; }
public virtual string set_name { get; set; }
public virtual string set_search_uri { get; set; }
public virtual string set_type { get; set; }
public virtual string set_uri { get; set; }
public virtual string set { get; set; }
public virtual int? story_spotlight { get; set; }
public virtual int? textless { get; set; }
public virtual int? variation { get; set; }
public virtual string variation_of { get; set; }
public virtual string watermark { get; set; }
public virtual DateTime? created_at { get; set; }
public virtual DateTime? updated_at { get; set; }
}
}
爆炸的代码:
#region Get
public List<Carte> getCardById(UInt64 cardId)
{
// cardId is 111
// Called by:
// UInt64 h = 111;
// var card = cardsProvider.getCardById(h);
try
{
sessione = factory.OpenSession();
//Build the Query to fetch ONLY the contacts for that user
var sqlQuery = sessione.CreateSQLQuery("SELECT * FROM carte WHERE custom_id = :custom_id");
//Substitute parameter userid after the : with the input userid
sqlQuery.SetParameter("custom_id", cardId);
//Fect all the records, transform them into the mapped class contacts, turned them into a list of Contacts (derived from the ISession class) and...well, cast it to list
return sqlQuery.SetResultTransformer(Transformers.AliasToBean<Carte>()).List<Carte>().ToList();
//This also explode
//var card = sessione.Get<Carte>(cardId);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (sessione.IsOpen)
sessione.Close();
}
}
#endregion
Nhibernate配置:
try
{
var cfg = new Configuration();
cfg.DataBaseIntegration(x => {
x.ConnectionString = Config.Config.getConfig().Connection.First().connectionStrig;
x.Driver<MySqlDataDriver>();
x.Dialect<MySQLDialect>();
});
cfg.AddAssembly(Assembly.GetExecutingAssembly());
this.factory = cfg.BuildSessionFactory();
}
catch(Exception ex)
{
throw ex;
}
数据库切片:
Db屏幕截图
你是否尝试过制作"sessione.Get(cardId("并得到相同的错误?(我想你会得到同样的错误(
根据文献记载;UInt64";对于nhibernate;Int64〃;。我认为问题与此有关。
我希望我帮了你!