c# - Changing selected objects inside a query -
I have need of a property is set within a square that LINQ-to-SQL query my first attempt a "setter "the method that is the object instance will return and thus, can be used in my selection was to be:
public partial class Foo {public Date time RetrievalTime {; Set; } Public Foo SetRetrievalTimeAndReturnSelf (Date Time Value) {Recovery Time = Value; This return; }} .... foo in DataContext.GetTable & lt; Foo & gt; Select foo.SetRetrievalTimeAndReturnSelf ();
Unfortunately, such a question throws an exception like this:. "System.NotSupportedException: method to change 'Foo.SetRetrievalTime (System.DateTime)' has no supported translation to SQL"
What results in inventory and no choice but to walk on it? The query is used in the custom "gate" method which is datacentax. Wrap the gatetail method, so it will be used as the basis for many other questions. Immediately after this change will not be optimal to convert a set result to a potentially large one list.
Update
Here's a better example of what I'm doing, updated with Jason's proposed solution:
Protected IQueryable & lt; T & gt; Go & lt; T & gt; () Where T: class, ISecurable {// DataContext.GetTable & lt all T records and associated security records on query = retrieved from the unit; T & gt; () DataContext.GetTable from userEntityAccess & lt; UserEntityAccess & gt; () Where userEntityAccess.SysUserId == CurrentUser.Id & amp; Amp; Entity.Id == User Antiquity AntideID & amp; UserEntityAccess.EntityClassName == Type (t) .Name Select New {unit, userEntityAccess}; query.AsEnumerable () return .Select (item = & gt; {item.entity.CanRead = item.userEntityAccess.CanRead; item.entity.CanWrite = item.userEntityAccess.CanWrite; item.entity.CanDelete = item.userEntityAccess.CanDelete ; Return item.nt;}). Eskenable (); } Public Interface Eyeshell {int id {get; Set; } Bool CanRead {get; Set; } Bool Canvrite {Receive; Set; } Bool CanDelete {get; Set; }}
UserEntityAccess is a cross-reference table between a user and a business object record (i.e. one entity). Each record is included in areas like "CanRead", "CanWrite", and "CanDelete", and determines whether a specific user can do with a specific record.
A marker interface is ISecurable which must be implemented by any LINQ-to-SQL domain class that requires access to this secure method.
var projection = data contexts. Gate Tables & lt; Foo & gt; .Asnumerable (). Select (f = & gt; f.SetRetrievalTimeAndReturnSelf ());
This is then the Foo
in the DataContext.GetTable & lt; Foo & gt;
SetRetrievalTimeAndReturnSelf
code for each instance of IEnumerable
Do you need to know that object, which was found for the database? This is possibly smelly.
Comments
Post a Comment