Unmei
How to effectively dispose unmanaged resources?
i have some questions about disposing objects in .NET.
I work with a .NET API that connects to a SQL Server database via Entity Framework.
Basically, the hierarchy of calls are: Controller -> Scoped Service -> Scoped Repository -> DbContext.
As we are increasing number of users of the API and our application isn't very optmized, i went into studying about disposing objects, specially unmanaged resources (those not "deletable" by GC right? How to know if a object is unmanaged btw?).
I wrote some questions in the code snippet bellow. As I'm still new to this (never needed to write explicitly dispose methods before), I'm open to opinions and experiences you all had in your projects and investigations!
12 replies
Is it possible to build a custom Expression<Func<T, bool>> by chaining "Or" operations to use in EF?
Hi all, this is my first post here.
I want to check if it's possbile to chain Expression.Or operations to be able to use it in EF 6 (Or in a
IEnumerable.Where()
in general.
Let me explain the context:
- I have two entities called Orders and Users. Users can create multiple orders, and one Order is related to one single User.
- Orders have a "CreatedDate" field (so that it is populated with DateTime.Now in the database) and also "CreatedBy" representing the username that created it.
- Users have a field called "DateDisabled" nullable. When it is null
, I can bring all his orders, but if it has a value, i will just bring orders dating from before he was disabled: order.DateCreated <= user.DateDisabled
.
To simplify:
a filter to bring orders from a single user would be :
since we can have many users, we would have many filter, one for each user:
var manyUsersOrders = _repository.Where(filter1 || filter2 || filter3 || ... || filterN);
Here comes the question: since it's not known how many users there are in the array, How can I create such an expression that chain Or
operations like that dinamically?
I tried to build Expressions and use Expression.Or
to join them together, but It returns a BinaryExpression
and I don't know exactly how to use it to build the final expression. Any help?30 replies