fluent-nhibernate

References/has-a mapping thru 3 tables

穿精又带淫゛_ 提交于 2019-12-11 06:16:31
问题 My model object Reading has a Location but it's not a direct relationship in the database. In the DB, this "has-a" relationship or "reference" spans 3 tables, as shown in this snip: My Reading maps to the ComponentReading table and i want my Location to map to the Location table. My ClassMap<Reading> class looks like this for now: public class ReadingMap : ClassMap<Reading> { public ReadingMap() { Table("ComponentReading"); Id(x => x.ID).Column("ComponentReadingId"); //References(x => x

Fluent NHibernate - HasOne With Where Clause

混江龙づ霸主 提交于 2019-12-11 05:47:34
问题 with Fluent NHibernate i can map a one to many relationship against my User class by saying: HasMany(x => x.Membership) .KeyColumn("UserID") .Where("Deleted = 0"); This works as expected that it only grabs the Membership records which have not been deleted. No say i have a field called Latest against the Membership where i know this would return one record per user, i'd like to be able to say: HasOne(x => x.CurrentMembership) .Where("Current = 1"); But there is no Where method. I know i could

Queries and Commits take longer as the session lives on

℡╲_俬逩灬. 提交于 2019-12-11 05:38:29
问题 I use Fluent NHibernate to import data into a SQL Server Database. I used Automapping on my entities (which worked perfectly) Fluently.Configure(nhibernateConfig_) .Mappings(map_ => map_.AutoMappings.Add(AutoMap .AssemblyOf<EntityMapping>(new AutomapConfiguration()) .UseOverridesFromAssemblyOf<EntityMapping>() .Conventions.AddFromAssemblyOf<EntityMapping>())); and use QueryOver to get data from the database public AttributeTranslation GetOrCreateAttributeTranslation(Attribute attribute_,

Fluent nHibernate Getting HasMany Items In Single Query

↘锁芯ラ 提交于 2019-12-11 04:58:37
问题 I have a Topic map which has many posts in it i.e… (At the bottom HasMany(x => x.Posts)) public TopicMap() { Cache.ReadWrite().IncludeAll(); Id(x => x.Id); Map(x => x.Name); *lots of other normal maps* References(x => x.Category).Column("Category_Id"); References(x => x.User).Column("MembershipUser_Id"); References(x => x.LastPost).Column("Post_Id").Nullable(); HasMany(x => x.Posts) .Cascade.AllDeleteOrphan().KeyColumn("Topic_Id") .Inverse(); *And a few other HasManys* } I have written a

Can Fluent NHibernate's AutoMapper handle Interface types?

半腔热情 提交于 2019-12-11 04:35:27
问题 I typed this simplified example without the benefit of an IDE so forgive any syntax errors. When I try to automap this I get a FluentConfigurationException when I attempt to compile the mappings - "Association references unmapped class IEmployee ." I imagine if I were to resolve this I'd get a similar error when it encounters the reference to IEmployer as well. I'm not opposed to creating a ClassMap manually but I prefer AutoMapper doing it instead. public interface IEmployer { int Id{ get;

Select N random records in SQL Server without repetition

对着背影说爱祢 提交于 2019-12-11 04:32:06
问题 How do I select N random records from a table at a time without repetition of records previously returned by the same operation? An obvious solution is: SELECT TOP 5 * FROM MyTable WHERE Id NOT IN (SELECT Id FROM PreviouslyReturned) ORDER BY newid() But wouldn't that be really inefficient as MyTable starts to grow? I have a long list of records and I require five records at a time for a turn-based game without repeating any of the records already pulled for the given game. Since I know

nhibernate mapping many rows to one object

a 夏天 提交于 2019-12-11 04:21:27
问题 i have a rather difficult mapping problem. EDIT: reformulated descritpion for historical reasons texts are not stored in a column as text, instead they are saved in tables. i have several tables with following structure: TABLE SomeEntityTexts ( id serial NOT NULL, key character varying(10), // \ linenumber integer, // / unique constraint type smallint, length smallint, // actual length of content string content character varying(80), PRIMARY KEY (id) ) text is saved as lines with arbitrary

assembly does not allow partially trusted callers

六月ゝ 毕业季﹏ 提交于 2019-12-11 04:06:42
问题 I am building a site using fluent NHibernate, which works just fine on the dev box. However, after I uploaded it to my host I get the following when trying to run it. "System.TypeInitializationException: The type initializer for 'NHibernate.ByteCode.Castle.ProxyFactory' threw an exception. ---> System.Security.SecurityException: That assembly does not allow partially trusted callers. Is this something I will need to resolve with the hosting company (CrystalTech)? Any help much appreciated.

Mapping Geometry from SQLServer2008 to .NET (NHibernate 4.0.0.4000)

那年仲夏 提交于 2019-12-11 04:01:37
问题 I try to map a SqlServer2008 geometry with FluentNHibernate. I am using NHibernate version 4.0.0.4000. I installed NHibernate.Spatial, NetTopologySuite, GeoAPI and NHibernate with FluentNhibernate all with NUget. My Fluent mapping looks like this: public class ArealMap: ClassMap<Areal> { public Areal() { Table("Areal"); Id(x => x.Id).Column("Id").GeneratedBy.Identity(); Map(x => x.Geometry).Column("Geometry").CustomType(typeof(MsSql2008GeometryType)); } } public class Areal { .... public

NHibernate MappingException: no persister for byte[]

半城伤御伤魂 提交于 2019-12-11 04:00:57
问题 I'm using NHibernate to store downloads in my MySQL database for an ASP.NET MVC website. I am using to classes. One called Download for the download itself and one called DownloadContent for the file itself (so I can load it easier when I just want to get the metadata). The data class declarations and mappings look like this: public class Download { public virtual string Id { get; set; } public virtual string OutFileName { get; set; } public virtual DownloadContent Contents { get; set; }