This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I would like to add a custom property and use it in queries like "normal" property. OrderStatus is enumeration. I cannot map the _statusId field to OrderStatus directly because of the database has Status reference table and already has Status property (assosiation). Is that possible to use this sintax - (o => o.StatusEnum == OrderStatus.Completed) for database queries?
var itWorks = UnitOfWork.Orders.Where(o => (OrderStatus)o.StatusId == OrderStatus.Completed).ToList(); var exception = UnitOfWork.Orders.Where(o => o.StatusEnum == OrderStatus.Completed).ToList();
I know that I should link the new property to the field. How can I do it if it's possible?
Here is the partial and initial classes
partial class Order { public OrderStatus StatusEnum { get { return (OrderStatus)Get(ref _statusId, "StatusId"); } set { Set(ref _statusId, (Int32)value, "StatusId"); } } }
public partial class Order : Entity<long> { [Column("STATUS_ID")] private long _statusId; [System.Diagnostics.DebuggerNonUserCode] public Status Status { get { return Get(_status); } set { Set(_status, value); } } [System.Diagnostics.DebuggerNonUserCode] public long StatusId { get { return Get(ref _statusId, "StatusId"); } set { Set(ref _statusId, value, "StatusId"); } } }
Thank you in advance!
|
|
|
The easiest thing to do is to implement StatusId as an enum instead of a long; this would save you having to have two properties. However this would require you to change the association to manual implementation (because the designer will always infer the identity type of the associated entity, and the designer doesn't support enum identity types). You can do this by setting Generate to FieldOnly and implementing the wrapper properties in partial classes, with the StatusId wrapper performing the cast to enum. Alternatively you should be able to do it by applying QueryPropertyAttribute to the _statusId field. QueryPropertyAttribute allows differently named properties to be mapped to fields for querying purposes. However once again you would need to break out the association into a manual implementation because QueryPropertyAttribute is currently supported only in code, not in the designer -- and at that point you might as well just make it an enum directly unless you really need to keep both properties. |
|
|
Thank you. I have applied the first approach. |
|