🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.pl.comp.lang.csharp
Article #21824

Re: [NH] many-to-many i session.Save(movie)

#21824
From: GrzybSon
Date: Thu, 04 Nov 2010 08:17
80 lines
3865 bytes
> Na szybko, Inverse na Filmie, a później dodawanie kategorii do
> filmu nie zahula ;-).

Trochę poszperałem i doszedłem do mapowania, które u mnie działa:

dla filmu ->

// ------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <!--Build: with lujan99@usa.net Nhibernate template-->
  <class name="nh.wypozyczalnia.Film,NH.Domain" table="film" lazy="true">
    <id name="Id" column="id" type="Decimal">
      <generator class="native" />
    </id>
         ...
    <bag name="Gatunki" table="gatunki_filmow" cascade="all">
      <key column="id_filmu" />
      <many-to-many class="nh.wypozyczalnia.Gatunek,NH.Domain" 
column="id_gatunku" />
    </bag>
  </class>
</hibernate-mapping>
// ------------------------------------------------------------------------------------------------------------------



dla gatunku ->
// ------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <!--Build: with lujan99@usa.net Nhibernate template-->
  <class name="nh.wypozyczalnia.Gatunek,NH.Domain" table="gatunek" 
lazy="true">
    <id name="Id" column="id" type="Decimal">
      <generator class="native" />
    </id>

 ...

    <bag name="Filmy" table="gatunki_filmow" inverse="true">
      <key column="id_gatunku" />
      <many-to-many class="nh.wypozyczalnia.Film,NH.Domain" 
column="id_filmu" />
    </bag>
  </class>
</hibernate-mapping>
// ------------------------------------------------------------------------------------------------------------------

i teraz elegancko działa kodzik:

GenericSingleton<DataProvider>.Instance.InTransaction(
                session =>
                {
                    movie.FormatFilmu = session.Load<FormatFilmu>(ff);
                    movie.RodzajTlumaczenia = 
session.Load<RodzajTlumaczenia>(tlumaczenie);

                    if (gatunki != null)
                    {
                        Gatunek gatunek;
                        foreach (decimal idGatunku in gatunki)
                        {
                            movie.Gatunki.Add(session.Load<Gatunek>(idGatunku));
                        }
                    }

                    session.Save(movie);
                });

> p.s. decimal jako typ klucza głównego to jest wybór świadomy? ;-)

Wybór świadomy dla szablonu z MyGeneration :)
W bazie PK jest typu numeric(18,0) co jest rozpoznawane jako konwertowane do 
decimala w narządzie.
A czym być to zastąpił?

--
Pozdro,
 Maćko 
Technical Details
Message-ID: <iatq6i$f3m$1@news.onet.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.nask.pl!news.nask.org.pl!news.onet.pl!not-for-mail
References: <iar8be$54q$1@news.onet.pl> <h9xwg0qecybu.eol8dng45ctj$.dlg@40tude.net>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.nask.pl!news.nask.org.pl!news.onet.pl!not-for-mail
From: "GrzybSon" <grzybson@poczta.fm>
Newsgroups: alt.pl.comp.lang.csharp
Subject: Re: [NH] many-to-many i session.Save(movie)
Date: Thu, 4 Nov 2010 09:17:23 +0100
Organization: http://onet.pl
Lines: 82
Message-ID: <iatq6i$f3m$1@news.onet.pl>
References: <iar8be$54q$1@news.onet.pl> <h9xwg0qecybu.eol8dng45ctj$.dlg@40tude.net>
NNTP-Posting-Host: 62-121-97-180.home.aster.pl
X-Trace: news.onet.pl 1288858642 15478 62.121.97.180 (4 Nov 2010 08:17:22 GMT)
X-Complaints-To: niusy@onet.pl
NNTP-Posting-Date: Thu, 4 Nov 2010 08:17:22 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-Antivirus: avast! (VPS 101103-2, 2010-11-03), Outbound message
X-Antivirus-Status: Clean
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit