Discussion:
[nhusers] How to map a class that derives from a base class with just a ID property?
c***@gmail.com
2017-12-14 07:37:45 UTC
Permalink
Thanks first!

I'm new to NHibernate. I use version 4.X.

I have a base entity class like this:
public abstract class EntityBase<TId>
{
public TId Id { get; set; }

// omit other method members
}

then, I have a derived class like this:
public class Product:EntityBase<int>
{
public string Name { get; set; }
public decimal Price { get; set }

// omit other members
}

Now, could anybody teach me how to map Id, Name, Price these three
properties into one data table like this:

-------------------------------------
Id | Name | Price
-------------------------------------

Thanks anyway!
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Abdul Samad
2017-12-17 13:57:31 UTC
Permalink
If you use Fluent NHibernate, You can create a ProductMap class which
automatically does few mappings except for ForiegnKeys.

Also if you dont want to use Fluent, then you may need to go with XML
Mapping files .hbm.

Please refer the below link for Fluent
https://github.com/jagregory/fluent-nhibernate/wiki/Fluent-mapping
Post by c***@gmail.com
Thanks first!
I'm new to NHibernate. I use version 4.X.
public abstract class EntityBase<TId>
{
public TId Id { get; set; }
// omit other method members
}
public class Product:EntityBase<int>
{
public string Name { get; set; }
public decimal Price { get; set }
// omit other members
}
Now, could anybody teach me how to map Id, Name, Price these three
-------------------------------------
Id | Name | Price
-------------------------------------
Thanks anyway!
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Gunnar Liljas
2017-12-17 20:43:13 UTC
Permalink
The fact that you inherit from EntityBase doesn't matter to NHibernate.
Just map the class as if it had contained the Id property itself. Note that
all properties must be "virtual".

/G
Post by Abdul Samad
If you use Fluent NHibernate, You can create a ProductMap class which
automatically does few mappings except for ForiegnKeys.
Also if you dont want to use Fluent, then you may need to go with XML
Mapping files .hbm.
Please refer the below link for Fluent https://github.com/
jagregory/fluent-nhibernate/wiki/Fluent-mapping
Post by c***@gmail.com
Thanks first!
I'm new to NHibernate. I use version 4.X.
public abstract class EntityBase<TId>
{
public TId Id { get; set; }
// omit other method members
}
public class Product:EntityBase<int>
{
public string Name { get; set; }
public decimal Price { get; set }
// omit other members
}
Now, could anybody teach me how to map Id, Name, Price these three
-------------------------------------
Id | Name | Price
-------------------------------------
Thanks anyway!
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Loading...