I have a class with 6 property:
public class ControllerValuesArgs:EventArgs
{
// debouncer for button
private static int btnCounter = 0;
// flag to send buttons
bool activeFlag = false;
/// <summary>
/// Default constructor.
/// </summary>
public ControllerValuesArgs()
{
// Reset buttons to initial state
ResetButtons();
}
/// <summary>
/// Gets or sets state of button 1.
/// </summary>
public bool Button1Pressed
{
get;
set;
}
/// <summary>
/// Gets or sets state of button 2.
/// </summary>
public bool Button2Pressed
{
get;
set;
}
/// <summary>
/// Gets or sets state of button 3.
/// </summary>
public bool Button3Pressed
{
get;
set;
}
/// <summary>
/// Gets or sets state of button 4.
/// </summary>
public bool Button4Pressed
{
get;
set;
}
/// <summary>
/// Gets or sets state of button 5.
/// </summary>
public bool Button5Pressed
{
get;
set;
}
/// <summary>
/// Gets or sets state of button 6.
/// </summary>
public bool Button6Pressed
{
get;
set;
}
I want to use the the property with true result inside to put it in a hashtable and converted to string.
What i try:
/// <summary>
/// Handler listening on Conontroller variables needed to calculate the expression.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">An object that contains no event data.</param>
public void ConontrollerValuesUpdate(object sender, EventArgs e)
{
ControllerValuesArgs conontrollerValuesArgs = new ControllerValuesArgs();
hashtable["UserInput"] = conontrollerValuesArgs.ToString();
CalculateExpression();
}
How can i call ore search for the true result in all property from that class and put it in the table?
This is similar to converting any object to ExpandoObject as ExpandObject implements IDictionary<string,object>.
This should give you dictionary with properties.
public static class DynamicExtensions
{
public static IDictionary<string, object> ToDynamicDictionary(this object value)
{
IDictionary<string, object> expando = new ExpandoObject();
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(value.GetType()))
expando.Add(property.Name, property.GetValue(value));
return expando;
}
}
Answer based on http://blog.jorgef.net/2011/06/converting-any-object-to-dynamic.html
Related
When writing TSVs from .Net objects file using CsvHelper, I would like to control column sort order using attributes.
When using the CsvHelper-provided Index(..) attribute, I am able to control serialization order, but the column header is suffixed with an index:
Model(s), inherited:
/// <summary>
/// Generic daily data
/// </summary>
public class DailyData
{
/// <summary>
///
/// </summary>
[CsvHelper.Configuration.Attributes.Index(-2, -2)]
public int IdDay {get;set;}
}
/// <summary>
/// Generic hou-on-a-day data
/// </summary>
public class HourlyData : DailyData
{
/// <summary>
///
/// </summary>
[CsvHelper.Configuration.Attributes.Index(-1)]
public byte IdHour { get; set; }
}
/// <summary>
///
/// </summary>
public class HourlyWeatherInfo : HourlyData
{
/// <summary>
///
/// </summary>
public double Temperature { get; internal set; }
}
Output:
IdDay1 IdHour1 Temperature
20220516 18 291.7
20220516 21 289.55
20220517 0 287.3
20220517 3 286.33
I am using negative numbers for indices because I want the base class to have their properties listed first without having to bother with serialization order in the derived classes (like HourlyWeatherInfo.
Am I overlooking functionality?
It feels a bit hacky, but this seems to work.
/// <summary>
/// Generic daily data
/// </summary>
public class DailyData
{
/// <summary>
///
/// </summary>
[CsvHelper.Configuration.Attributes.Index(-2,-3)]
public int IdDay {get;set;}
}
/// <summary>
/// Generic hou-on-a-day data
/// </summary>
public class HourlyData : DailyData
{
/// <summary>
///
/// </summary>
[CsvHelper.Configuration.Attributes.Index(-1,-2)]
public byte IdHour { get; set; }
}
/// <summary>
///
/// </summary>
public class HourlyWeatherInfo : HourlyData
{
/// <summary>
///
/// </summary>
public double Temperature { get; internal set; }
}
Tldr;
I have a object that extends from another object.
/// <summary>
/// Represents the result of an operation
/// </summary>
[DataContract]
public class ApiResult<T> : ApiResult
{
/// <summary>
/// The requested data
/// </summary>
[DataMember]
public T Data { get; private set; }
/// <summary>
/// Test
/// </summary>
[DataMember]
public string Test { get; private set; }
Every property of ApiResult is documented, but not the properties of ApiResult<T>:
Why is the documentation description blank for a extended object? I expected that my <summary> is used here. How can I make it show?
More Details
Here is the full code:
/// <summary>
/// Represents the result of an operation
/// </summary>
//[DataContract(Name = "ApiResult")]
public class ApiResult
{
/// <summary>
/// Indicates if the operation was performed successfull. If an error occured more Information are available in ErrorCode and Message.
/// </summary>
[DataMember]
public bool IsSuccess { get; private set; }
/// <summary>
/// A programmable static reason, if the operation was not successfull. This can be ignored on successfull state.
/// </summary>
[DataMember]
public int ErrorCode { get; private set; }
/// <summary>
/// Additional information about the error, if the operation was not successfull. This is only for Information purpose. Use the ErrorCode for business conditions instead.
/// </summary>
[DataMember]
public string Message { get; private set; }
/// <summary>
/// Creates a Success Result
/// </summary>
public ApiResult()
{
IsSuccess = true;
ErrorCode = 0;
Message = "ok";
}
/// <summary>
/// Creates a Error Result
/// </summary>
/// <param name="errorCode">The error code</param>
/// <param name="message">The message</param>
public ApiResult(int errorCode, string message)
{
IsSuccess = false;
ErrorCode = errorCode;
Message = message;
}
}
/// <summary>
/// Represents the result of an operation
/// </summary>
//[DataContract(Name = "ApiResult")]
public class ApiResult<T> : ApiResult
{
/// <summary>
/// The requested data
/// </summary>
[DataMember]
public T Data { get; private set; }
/// <summary>
/// Test
/// </summary>
[DataMember]
public string Test { get; private set; }
/// <summary>
/// Creates a Success Result without having an actualy Result
/// <remarks>This constructor should not be used. A parameterless constructor is needed for the automatic generation of a Documentation Example.</remarks>
/// </summary>
//[EditorBrowsable(EditorBrowsableState.Never)]
//[Obsolete("Use the nongeneric version of ApiResult instead. This CTOR is only to support XmlSerialization.")]
public ApiResult()
{
}
/// <summary>
/// Creates a Success Result
/// </summary>
/// <param name="data">The data</param>
public ApiResult(T data)
{
Data = data;
}
/// <summary>
/// Creates a Error Result
/// </summary>
/// <param name="errorCode">The error code</param>
/// <param name="message">The message</param>
public ApiResult(int errorCode, string message) : base(errorCode, message)
{
}
}
And here my Method signature:
public ApiResult<CardInfo> GetCardInfo(string cardNumber)
Just in case, here is my CardInfo-class:
/// <summary>
/// Information about a card
/// </summary>
public class CardInfo
{
/// <summary>
/// Card Type
/// </summary>
public string CardType { get; set; }
/// <summary>
/// Represents the current credit on card.
/// Prepaid cards: CurrentValue represents the current credit on card.
/// Postpaid: CurrentValue represents the monthly available credit amount.
/// </summary>
public decimal CurrentValue { get; set; }
}
My Question is about the automatic generated Help Page in Web API 2. The <summary> is ignored on the helppage, if the Class is extended.
This should work and it's very basic. My json string is (from the debugger):
json "{\"companyId\":0,\"companyName\":\"Windward 3\",\"apiKey\":null,\"isEnabled\":false,\"isActive\":false,\"accruedRtusThisMonth\":0,\"billedRtusThisMonth\":0,\"overageChargesThisMonth\":0.0,\"pricingMode\":3,\"discount\":null,\"billingMode\":1,\"maxAdditionalMonthlyCharge\":123.0,\"billing\":{\"personId\":0,\"companyId\":0,\"isActive\":false,\"isAdmin\":false,\"isBilling\":false,\"firstName\":\"David\",\"lastName\":\"Thielen\",\"address1\":\"1 Main St.\",\"address2\":null,\"city\":\"Boulder\",\"state\":\"CO\",\"country\":\"USA\",\"postalCode\":\"80301\",\"phone\":\"123-456-7890\",\"email\":\"david#windward.net\",\"password\":\"tree\"},\"creditCard\":{\"cardNumber\":\"4111111111111111\",\"expiration\":\"2015-02-18T23:37:01.3135786Z\",\"cvv\":\"123\",\"useCardPerson\":false,\"cardPerson\":null},\"nextBaseBillingDate\":\"0001-01-01T00:00:00\",\"nextOverageBillingDate\":\"0001-01-01T00:00:00\",\"billingStatus\":0,\"billingErrorDate\":null,\"deactivateDate\":null,\"deleteDate\":null}" string
My code is as follows:
CompanyWrapper companyWrapper = JsonConvert.DeserializeObject<CompanyWrapper>(json,
new JsonSerializerSettings());
And the CompanyWrapper class is:
public class CompanyWrapper
{
/// <summary>
/// For the JSON population.
/// </summary>
public CompanyWrapper()
{
}
/// <summary>
/// For unit tests
/// </summary>
public CompanyWrapper(string companyName, PricingPlan.PRICING_MODE pricingMode, Company.BILLING_MODE billingMode, decimal maxAdditionalMonthlyCharge, PersonWrapper billing, CreditCardWrapper creditCard)
{
this.companyName = companyName;
this.pricingMode = pricingMode;
this.billingMode = billingMode;
this.maxAdditionalMonthlyCharge = maxAdditionalMonthlyCharge;
this.billing = billing;
this.creditCard = creditCard;
}
/// <summary>
/// The primary key. This is auto-generated in the database.
/// </summary>
public int companyId { get; private set; }
/// <summary>
/// The company name. This cannot be changed.
/// </summary>
public string companyName { get; private set; }
...
}
On return companyWrapper.companyName == null. That should be assigned. What am I missing?
thanks - dave
You need to make the property setters public.
I'm trying to create a new post in my site, but for some reason, EF throws the following error:
A relationship from the 'PostAttributeValue_Definition' AssociationSet
is in the 'Deleted' state. Given multiplicity constraints, a
corresponding 'PostAttributeValue_Definition_Source' must also in the
'Deleted' state.
Since I'm not trying to delete anything and I didn't changed or removed any value, I'm confused why I'm getting this error.
My db context contains the following:
modelBuilder.Entity<PostAttributeValue>().HasRequired<PostAttributeDefinition>(a => a.Definition).WithOptional().Map(m =>
{
m.MapKey("RelatedAttributeDefinitionId");
}).WillCascadeOnDelete(false);
/* Category(required) to PostAttributeDefinition(many) */
modelBuilder.Entity<PostAttributeDefinition>().HasRequired<Category>(a => a.OwnerCategory).WithMany(c => c.AttributeDefinitions).Map(m =>
{
m.MapKey("OwnerCategoryId");
}).WillCascadeOnDelete(true);
My publish method looks like this:
//
// POST: /Post/Publish/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Publish(int? id, PublishViewModel model)
{
if (!id.HasValue || id.Value < 1)
{
return HttpNotFound();
}
var category = this.categoryService.Find(id.Value);
if (category == null)
{
return HttpNotFound();
}
if (ModelState.IsValid)
{
List<PostAttributeValue> attributes = new List<PostAttributeValue>();
foreach (var attribute in model.Attributes)
{
attributes.Add(new PostAttributeValue()
{
Definition = attribute.Definition,
RawValue = attribute.Value.Serialize()
});
}
Post post = new Post()
{
Title = model.Title,
Description = model.Description,
City = model.City.City,
Brokerage = model.Brokerage,
Location = model.Location,
RequestedPrice = model.Price.Value,
ParentCategory = category,
Attributes = attributes,
};
this.postService.PublishPost(post);
return RedirectToAction("ImageSelection", new { id = post.PostIdentifier });
}
return View(model);
}
The error is been thrown from the Repository class Add() method, which looks like this:
public TEntity Add(TEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
try
{
var result = this.Entity.Add(entity);
this.context.SaveChanges();
return result;
}
catch
{
var deletedEntries = context.ChangeTracker.Entries().Where(e => e.State != EntityState.Added && e.State != EntityState.Unchanged);
throw;
}
}
Because the exception related to entities in deleted state, I've wrote this linq query that checks for entities that're not unchanged or added, but it returns zero results... I really
don't know why I'm getting this error.
Just to note, I'm using proxy entities, and from inspection in the debugger everything seems OK - the entire values are been filled in as excepted.
Hope somebody can help me figure it out. Thanks! :)
Edited:
The PostAttributeDefinition model class, which is a class that describes a custom attribute definition (each category can have different custom attributes - for example, "TV Shows" can have a custom attribute "Number of episodes" while Movies "IMDB rank", for example)
public class PostAttributeDefinition
{
#region Members
private Lazy<object> lazyDataValue = null;
private Lazy<PostAttributeDefinitionValidationRules> lazyValidatorValue = null;
private Type cachedDataType;
#endregion
/// <summary>
/// The filter name
/// </summary>
[Key]
public int DefinitionId { get; set; }
/// <summary>
/// The owner category
/// </summary>
[Required]
public virtual Category OwnerCategory { get; set; }
/// <summary>
/// The filter title
/// </summary>
[Required]
public string Title { get; set; }
/// <summary>
/// Metadata enum that provides extra data about the data type
/// </summary>
public PostAttributeTypeMetadata TypeMetadata { get; set; }
/// <summary>
/// Bitwise metadata that provides data about the object in display mode
/// </summary>
public PostAttributeDisplayModeMetadata DisplayModeMetadata { get; set; }
public PostAttributeEditorType EditorType { get; set; }
/// <summary>
/// The attribute raw default value
/// </summary>
[Required]
public byte[] RawDataValue { get; set; }
/// <summary>
/// The attribute raw associated validation attributes
/// </summary>
/// <remarks>
/// This field is used only by EF.
/// YES - It's against DDD rules, and I need to seperate it. setting it in TODO.
/// </remarks>
public byte[] RawValidationRules { get; set; }
/// <summary>
/// Is this field required
/// </summary>
/// <remarks>
/// This field does not relate to the validation rules since we should check it
/// only in creation / modification of the post and not in search for example.
/// </remarks>
public bool IsRequired { get; set; }
/// <summary>
/// The attribute validators
/// </summary>
public PostAttributeDefinitionValidationRules ValidationRules
{
get
{
if (lazyValidatorValue == null)
{
lazyValidatorValue = new Lazy<PostAttributeDefinitionValidationRules>(() =>
{
if (this.RawValidationRules == null || this.RawValidationRules.Length == 0)
{
return new PostAttributeDefinitionValidationRules();
}
return this.RawValidationRules.Deserialize() as PostAttributeDefinitionValidationRules;
});
}
return lazyValidatorValue.Value;
}
set
{
this.RawValidationRules = value.Serialize();
this.lazyValidatorValue = null;
}
}
/// <summary>
/// Get the stored object data type
/// </summary>
public Type ValueDataType
{
get
{
// Make sure we've loaded the serialized value
if (lazyDataValue == null)
{
RetriveDataValue();
}
return cachedDataType;
}
}
#region Value content
/// <summary>
/// Store the attribute default value
/// </summary>
/// <typeparam name="TType">The default value type</typeparam>
/// <param name="value">The default value</param>
/// <returns>Fluent style writing - returning the same object</returns>
public PostAttributeDefinition StoreDataValue<TType>(TType value)
{
// In case of empty value, we need to defaultize it
if (value == null)
{
value = value.DefaultizeNullableValueForSerialize<TType>();
}
// Store as bytes
RawDataValue = value.Serialize<TType>();
// Reset the lazy cached value
lazyDataValue = null;
// Fluent style returned value
return this;
}
/// <summary>
/// Retrive the item default value
/// </summary>
/// <typeparam name="TType">The item default value data type</typeparam>
/// <returns>The item default value</returns>
/// <exception cref="InvalidOperationException">Thrown in case the raw value is null or empty.</exception>
public TType RetriveDataValue<TType>()
{
return (TType)RetriveDataValue();
}
/// <summary>
/// Retrive the item default value
/// </summary>
/// <returns>The item default value</returns>
/// <exception cref="InvalidOperationException">Thrown in case the raw value is null or empty.</exception>
public object RetriveDataValue()
{
// Make sure that we've loaded the lazy value
if (lazyDataValue == null)
{
lazyDataValue = new Lazy<object>(() =>
{
// Deserialize
var value = RawDataValue.Deserialize();
// Remve defaultize in case we've done that (by the way, we're caching the type
// in order to retrive it in case of null value)
value = value.ReverseDefaultizeNullableValueForDeSerialize(out cachedDataType);
// Return it
return value;
});
}
// Return the cached lazy data value
return lazyDataValue.Value;
}
#endregion
}
The PostAttributeValue class, which I wish to save and causes the problems is:
public class PostAttributeValue
{
/// <summary>
/// The attribute value id
/// </summary>
[Key]
public int AttributeValueId { get; set; }
/// <summary>
/// The value owner post
/// </summary>
public virtual Post OwnerPost { get; set; }
/// <summary>
/// The value attribute definition id
/// </summary>
//public int RelatedAttributeDefinitionId { get; set; }
/// <summary>
/// The value attribute definition
/// </summary>
public virtual PostAttributeDefinition Definition { get; set; }
/// <summary>
/// The stored raw value
/// </summary>
public byte[] RawValue { get; set; }
#region Value content
/// <summary>
/// Check if there's anything stored in the raw value
/// </summary>
/// <returns>Boolean value indicates if there's anything stored in the raw value</returns>
public bool HasValue()
{
return RawValue != null;
}
/// <summary>
/// Retrive the item value
/// </summary>
/// <typeparam name="TType">The item default value data type</typeparam>
/// <returns>The item value</returns>
/// <exception cref="InvalidOperationException">Thrown in case the raw value is null or empty.</exception>
public TType RetriveValue<TType>()
{
return (TType)RetriveValue();
}
/// <summary>
/// Retrive the item value
/// </summary>
/// <returns>The item value</returns>
/// <exception cref="InvalidOperationException">Thrown in case the raw value is null or empty.</exception>
public object RetriveValue()
{
if (RawValue == null)
{
throw new InvalidOperationException("Could not deserialize the value since there's nothing in the raw value.");
}
return RawValue.Deserialize();
}
#endregion
}
Note that I'm using a ViewModel for the attributes (model.Attributes is an IEnumerable)
public class PostAttributeViewModel
{
[ReadOnly(true)]
[Editable(false)]
public PostAttributeDefinition Definition { get; set; }
[Required]
public int DefinitionId { get; set; }
[Required]
public string DefinitionVertificationToken { get; set; }
public object Value { get; set; }
}
The Definition attribute, that I'm assigning and mapping to the PostAttributeValue model is auto-filled by EF.
I am creating an ICriteria query for this equivalent sql query.
SELECT fCustomerID,
ISNULL(
(SELECT SUM(payinv.fAmount) AS Expr1
FROM dbo.tARPayment AS pay
INNER JOIN dbo.tARPaymentInvoice AS payinv ON pay.fPaymentID = payinv.fPaymentID
INNER JOIN dbo.tARInvoice AS inv ON payinv.fInvoiceID = inv.fARInvoiceID
WHERE (pay.fIsPosted = CASE pay.fPaymentType WHEN 'CM' THEN 0 WHEN 'EPD' THEN 0 ELSE 1 END)
AND (inv.fCustomerID <> dbo.tARCustomer.fCustomerID)
AND (pay.fCustomerID = dbo.tARCustomer.fCustomerID)), 0)
FROM dbo.tARCustomer
GROUP BY fCustomerID
But I am not getting anyway that how can I generate equivalent nhibernate ICriteria query.
This is payment class
public partial class tARPayment
{
#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="tARPayment"/> class.
/// </summary>
public tARPayment()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="tARPayment"/> class.
/// </summary>
/// <param name="fPaymentID">The fPaymentID of guid type.</param>
public tARPayment(System.Guid fPaymentID)
{
this.ID = fPaymentID;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets payment id.
/// </summary>
public virtual System.Guid fPaymentID { get; set; }
/// <summary>
/// Gets or sets fCustomerID.
/// </summary>
public virtual System.Guid fCustomerID { get; set; }
/// <summary>
/// Gets or sets check number.
/// </summary>
public virtual string fCheckNumber { get; set; }
/// <summary>
/// Gets or sets amount.
/// </summary>
public virtual decimal fAmount { get; set; }
/// <summary>
/// Gets or sets customer detail.
/// </summary>
public virtual tARCustomer Customer { get; set; }
public virtual IList<tARPaymentInvoice> PaymentInvoices { get; set; }
#endregion
#region Methods
/// <summary>
/// partial class for payment.
/// </summary>
/// <returns>The method get code.</returns>
public override int GetHashCode()
{
return ID.GetHashCode();
}
#endregion
}
This is a invoice class
public partial class tARInvoice
{
#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="tARInvoice"/> class.
/// </summary>
public tARInvoice()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="tARInvoice"/> class.
/// </summary>
/// <param name="fARInvoiceID">The fARInvoiceID.</param>
public tARInvoice(System.Guid fARInvoiceID)
{
this.ID = fARInvoiceID;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets fARInvoiceID.
/// </summary>
public virtual Guid fARInvoiceID { get; set; }
/// <summary>
/// Gets or sets fCustomerID.
/// </summary>
public virtual Guid fCustomerID { get; set; }
/// <summary>
/// Gets or sets Delivery Method.
/// </summary>
public virtual string fDeliveryMethod { get; set; }
/// <summary>
/// Gets or sets Invoice Number.
/// </summary>
public virtual int? fARInvoiceNumber { get; set; }
public virtual tARCustomer Customer { get; set; }
public virtual IList<tARPaymentInvoice> PaymentInvoices { get; set; }
#endregion
#region Methods
/// <summary>
/// retrieve Hash Code.
/// </summary>
/// <returns>The method get code.</returns>
public override int GetHashCode()
{
return ID.GetHashCode();
}
#endregion
}
This is a payment invoice class.
public partial class tARPaymentInvoice
{
#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="tARPaymentInvoice"/> class.
/// </summary>
public tARPaymentInvoice()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="tARPaymentInvoice"/> class.
/// </summary>
/// <param name="fPaymentInvoiceID">The Invoice ID.</param>
public tARPaymentInvoice(System.Guid fPaymentInvoiceID)
{
this.ID = fPaymentInvoiceID;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets fPaymentInvoiceID.
/// </summary>
public virtual System.Guid fPaymentInvoiceID { get; set; }
/// <summary>
/// Gets or sets fPaymentID.
/// </summary>
public virtual System.Guid fPaymentID { get; set; }
/// <summary>
/// Gets or sets fInvoiceID.
/// </summary>
public virtual System.Guid fInvoiceID { get; set; }
/// <summary>
/// Gets or sets tARPayment.
/// </summary>
public virtual tARPayment Payment { get; set; }
/// <summary>
/// Gets or sets tARInvoice.
/// </summary>
public virtual tARInvoice Invoice { get; set; }
#endregion
#region Methods
/// <summary>
/// get hash codes.
/// </summary>
/// <returns>The hash code.</returns>
public override int GetHashCode()
{
return ID.GetHashCode();
}
#endregion
}
Rather than converting the above query to LINQ or HQL, I would recommend making the query into a view, and then using NHibernate to query that view.
SQL
CREATE VIEW vCustomerAmount AS
SELECT fCustomerID,
ISNULL(
(SELECT SUM(payinv.fAmount) AS Expr1
FROM dbo.tARPayment AS pay
INNER JOIN dbo.tARPaymentInvoice AS payinv ON pay.fPaymentID = payinv.fPaymentID
INNER JOIN dbo.tARInvoice AS inv ON payinv.fInvoiceID = inv.fARInvoiceID
WHERE (pay.fIsPosted = CASE pay.fPaymentType WHEN 'CM' THEN 0 WHEN 'EPD' THEN 0 ELSE 1 END)
AND (inv.fCustomerID <> dbo.tARCustomer.fCustomerID)
AND (pay.fCustomerID = dbo.tARCustomer.fCustomerID)), 0) [Amount]
FROM dbo.tARCustomer
GROUP BY fCustomerID
C# DTO
public class CustomerAmount
{
public int fCustomerID { get; set; }
public decimal Amount { get; set; }
}
Query
List<CustomerAmount> customerAmounts = session.Query<CustomerAmount>().ToList();
Not sure about nHibernate, but does this rewritten query help get the same answer and is something you can run with easier?
SELECT T.fCustomerID,
coalesce( SUM( payinv.fAmount ), 0 ) as SumAmt
FROM
dbo.tARCustomer T
JOIN dbo.tARPayment AS pay
ON T.fCustomerID = pay.fCustomerID
AND pay.fIsPosted = CASE pay.fPaymentType
WHEN 'CM' THEN 0
WHEN 'EPD' THEN 0
ELSE 1 END
JOIN dbo.tARPaymentInvoice AS payinv
ON pay.fPaymentID = payinv.fPaymentID
INNER JOIN dbo.tARInvoice AS inv
ON payinv.fInvoiceID = inv.fARInvoiceID
AND inv.fCustomerID <> T.fCustomerID
GROUP BY
T.fCustomerID