Well, I have a ClassMap
like this for my mapping in FluentNHibernate
public class AbNopCommereceMap : ClassMap<AbNopCommerece>
{
public AbNopCommereceMap()
{
Table("AbNopCommerece");
Id(d => d.Id).CustomSqlType("BIGINT").GeneratedBy.Native();
Map(d => d.Name).CustomSqlType("NVARCHAR(100)").Unique().Not.Nullable();
Map(u => u.PublisherName);
Map(u => u.Author);
Map(u => u.Country);
Map(u => u.LastModifiedByFullName).Formula("(SELECT b.FirstName +' '+ b.LastName FROM Users b WHERE b.Id=CreatedBy)");
Map(d => d.IsActive);
Map(d => d.IsDeleted);
Map(d => d.IsLocked);
Map(d => d.CreatedBy).CustomType<TypedAggregateReferenceType<User>>();
Map(d => d.CreatedByDate);
Map(d => d.LastModifiedBy).CustomType<TypedAggregateReferenceType<User>>();
Map(d => d.LastModifiedByDate);
Map(d => d.Organization).Column("OrganizationId").CustomType<TypedAggregateReferenceType<Organization>>();
Cache.Region("General").NonStrictReadWrite();
ApplyFilter<OrganizationFilter>();
}
}
Here LastModifiedByFullName
is my User which I am selecting from the database, I want to execute a stored procedure here which I have already in my SQL server like
CREATE PROCEDURE pop_use(@id int)
as
DECLARE @FullName NVARCHAR(MAX)
SET @FullName = ''
SELECT @FullName = FirstName + ' '+ LastName FROM Users WHERE Id = @UserId
I have gone through this question1, question2 but they have used made a new function or XML to retrieve the value from data base. So, my question is, as I NHibernate
has already provide some feature like Format
by which I am getting the value from database directly, therefore is there any way in ClassMap to execute the stored Procedure
and let not me do some repetitive code again inside ClassMap
. In a word I am seeking for any way to collect the data from database through previously defined particular store procedure and add it into model.