You can declare this on an interface: public interface ICanDelete { bool IsDeleted {get;set;} } and let implicit interface implementation work its magic. Then the question becomes: "how to let it know that my entities implement this interface? ".
Two options: add a partial class per entity (in a different file): partial class Customer : ICanDelete {} partial class Order : ICanDelete {} edit the dbml to specify this interface as the base class: Database EntityBase="Some.NameSpace. ICanDelete (this makes LINQ-to-SQL's code-generation add the : Some.NameSpace. ICanDelete for you) Then just use this interface in the generic clause: where T : ICanDelete.
You can declare this on an interface: public interface ICanDelete { bool IsDeleted {get;set;} } and let implicit interface implementation work its magic. Then the question becomes: "how to let it know that my entities implement this interface? ".
Two options: add a partial class per entity (in a different file): partial class Customer : ICanDelete {} partial class Order : ICanDelete {} edit the dbml to specify this interface as the base class: (this makes LINQ-to-SQL's code-generation add the : Some.NameSpace. ICanDelete for you) Then just use this interface in the generic clause: where T : ICanDelete.
Perfet that worked for me, with a very minimal code change. – Jobi Joy Nov 14 '09 at 21:08.
1) Define ISoftDelete public interface ISoftDelete { bool IsDeleted { get; set; } } 2) Create partial classes for all your entities public partial class MyLinqEntity : ISoftDelete { } public partial class MyOtherLinqEntity : ISoftDelete { } public partial class MyFurtherLinqEntity : ISoftDelete { } 3) Add your interface to the generic type restriction public abstract class CRUDOperations : where T is ISoftDelete.
– Jobi Joy Nov 14 '09 at 20:29 Yep. There are other ways of doing this in the designer, but I prefer this method as I'll have all these partials I can use to modify my entities. Also, if I have to ditch the DBML and start over again (happens more than I would like) I won't have to redo all my customization work.
– Will? Nov 14 '09 at 20:31 IIRC, you can't do this in the designer - you have to hand-edit the dbml. – Marc Gravell?
Nov 14 '09 at 20:33.
I am doing a CRUD operation on Database generated class(using LINQ2SQL) in my WPF application. All of my DB tables have IsDelete property exists. So I want to define an abstract/interface class to do the SoftDelete().
My question here is, how can I define my Generic class in such a way as to access T. IsDelete = true? Where T is DB generated Table classes by LINQ To SQL (DBML), which I cant impose an Interface or base class on top of it?.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.