Limiting the results of System.Data.Linq.Table <T>

I am trying to inherit from my generated datacontext in LinqToSQL - something like this

public class myContext : dbDataContext {
 public System.Data.Linq.Table<User>() Users {
  return (from x in base.Users() where x.DeletedOn.HasValue == false select x);
 }
}

But my Linq statement returns an IQueryable that cannot be applied to a table. Does anyone know a way to limit the contents of Linq.Table. I try to be sure that in any place where my Users table is available, it does not return those marked as deleted. Perhaps I will do it all wrong - any suggestions will be very grateful.

Hal

+3
source share
8 answers

Another approach would be to use views.

CREATE VIEW ActiveUsers as SELECT * FROM Users WHERE IsDeleted = 0

linq to sql, , . , DeletedOn, , , .

+2

, .. DeletedUsers ActiveUsers, , . ActiveSysers Users.OfType, - .

, ?

Users.OfType<ActiveUsers>

,

+1

DataContext, . "" , , . , :

from item in All
where ...
select item

:

public IQueryable<T> All
{
    get { return MyDataContext.GetTable<T>.Where(entity => !entity.DeletedOn.HasValue); }
}
+1

, , , LINQ to SQL . , proc Server Explorer LINQ to SQL.

0

, , IQueryable,

t _db.
t;

tableRepository.GetAllXXX(); tableRepository.GetAllNonDeletedXXX(); where, . , .

0

, , :

, DeletedOn, - . ( ) StringTemplate , ( /).

DeletedOn . ( 30 - ouch), , Value Dcriminator Value Value.

StringTemplate, , , , StringTemplate [user] .

0

, , - , . . , , , .

, , .

, , , , , , , . , Visual Studio 2008 linq to sql.dbml.

0

, /, . , dbml , . , , .

, .

0
source

Source: https://habr.com/ru/post/1697060/


All Articles