I use an abstract Entity
class which contains a Guid:
public abstract class Entity
{
public /*virtual*/ Guid Id { get; set; }
}
Suppose I also have a class like:
public class Post : Entity
{
public String Title { get; set; }
public String Content { get; set; }
public DateTime Timestamp { get; set; }
}
How do I properly map Post
class using xml-mapping? I'm asking about Id.
nhibernate Mappings Xml Mappings It is a syntax xml file which contains the metadata required for the object/relational mapping. The metadata includes declaration of persistent classes and the mapping of properties (to columns and foreign key relationships to other entities) to database tables.
Fluent NHibernate offers an alternative to NHibernate's standard XML mapping files. Rather than writing XML documents, you write mappings in strongly typed C# code. This allows for easy refactoring, improved readability and more concise code.
<id name="Id">
<generator class="guid"/>
</id>
This will generate Guids on the client using the Guid.NewGuid()
method.
Alternative generators are:
NEWID()
on SQL serverI would recommend guid.comb for most applications that use Guid identifiers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With