.net - Overriding entity caching/change-tracking behaviour in Linq to SQL -
I think the original question might have been rotated very long with too much unnecessary details, so it My effort is simple to do
I am looking for a medium to do any of the tasks given below. I need to do only one, not all. If anyone knows any of these, please answer. So, it is possible to do any of the following in SQL:
-
A
via DataContext
byExecuteQuery
Remove> orExecuteMethodCall
without tracking those entities? -
ExecuteQuery
orExecuteMethodCall
and guarantee that I always receive fresh copies of results obtained from the database, even if Only those institutions have already been recovered and they are already in the identity cache? -
Do not direct Linq to SQL
Restrictions:
-
Refresh
method is out of question; The number of institutions is large and it will become a performance disaster. -
I just do not have
object tracking enabled
tofalse
, becausedatacontax
After executing it does not allow setting it back totrue
, and I need some of institutions -
I can not even remove the original
DataContext
and can not use a new one; I should be able to do this in the middle of the transaction.
This is starting to cause a serious problem, and I really feel that the default behavior is malicious if I execute an ad-hoc query or stored procedure So, I hope that the results I get are the exact result, which was given by the query that was said. It only makes sense; If I want old, stale entities, why would I go to the database to bring them back?
At the moment, my work is either (a) a new DataContext
specifically for query and override transaction segregation level, or (B) return type "DTO" Which is similar to the unit in every way, but without [table]
attribute, and map it is in the original unit using Automaker
I have been able to come up with a viable long term solution for this issue. This is not ideal at all, but it has been relatively painless for working so far and is less scary than the option.
Because these questions are pure SQL - they all ExecuteQuery
for inline SQL or ExecuteMethodCall
for stored procedures - I have decided that when I do not want to know the DataContext
for example "raw" ado About some institutions
Of course, the examples of IDCCommand and manual mapping will pass through IDataReader
, so I spent a few hours writing a code, heavy for me To carry a load, coding a library, "code" idb comma , an automatic "fluent"
for LinqDataReaderMapper, which uses MetaModel
Therefore, I want to overload the existing institutions without making amendments and to speed up writing simple questions. Extensions can I use a bunch of methods.
At the end of the day, I am writing something like this:
var result = context. Connection Commands ("Select Column 1, Table 2" from column 2, where "Filter Filter 1 = @ Ultimate 1 and FilterCol2 = @ Ultimate 2"). Parameter (P = & gt; P. Name ("Para 1"). Value (some value), P = & gt; P. Name ("Para 2"). Value (some other value)). Exact Reader () Map (context mapping). & Lt; MyEntity & gt; ();
Or just this:
var result = context .ExecuteQueryRaw & lt; MyEntity & gt; (CommandType.StoredProcedure, "SomeProc", new {Param1 = someValue, Param2 = some other values});
I am not posting the entire code for it - it is too long and I think it will be just a big tl, dr at this point - But the main idea is that they both have a IEnumerable & lt; MyEntity & gt;
return, and because they are being copied directly from the IDataReader
, they are essentially separate entities - Datacontax
about any direct There is no knowledge and therefore neither can block the results nor track them after the fact.
Therefore, the problem was resolved partially, though it would be even better if I just get DataContext
to behave yourself.
Comments
Post a Comment