Click here to Skip to main content
15,889,096 members
Home / Discussions / C#
   

C#

 
Questionmethods to use to build modular application Pin
Droiddr14-May-15 4:05
Droiddr14-May-15 4:05 
AnswerRe: methods to use to build modular application Pin
Pete O'Hanlon14-May-15 4:58
mvePete O'Hanlon14-May-15 4:58 
GeneralRe: methods to use to build modular application Pin
Droiddr14-May-15 5:42
Droiddr14-May-15 5:42 
GeneralRe: methods to use to build modular application Pin
Pete O'Hanlon14-May-15 22:05
mvePete O'Hanlon14-May-15 22:05 
GeneralRe: methods to use to build modular application Pin
Droiddr15-May-15 2:47
Droiddr15-May-15 2:47 
GeneralRe: methods to use to build modular application Pin
Pete O'Hanlon15-May-15 3:23
mvePete O'Hanlon15-May-15 3:23 
QuestionMessage Removed Pin
14-May-15 3:16
professionalN_tro_P14-May-15 3:16 
AnswerRe: Reflection DbSet Remove Pin
Richard Deeming14-May-15 4:41
mveRichard Deeming14-May-15 4:41 
Xaotiq wrote:
var dbSets = props.Where(prop => prop.PropertyType == typeof (DbSet<>));

You can't compare the property type to a generic type definition. You'll need to check whether the property type is a generic type, and then compare its generic type definition:
C#
var dbSets = props.Where(prop => prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(DbSet<>));

The easiest solution is probably to use the non-generic Set method to retrieve a non-generic DbSet from the context:
C#
var entityTypes = typeof(YourContext)
    .GetProperties(BindingFlags.Public | BindingFlags.Instance)
    .Where(p => p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(DbSet<>))
    .Select(p => p.PropertyType.GenericTypeArguments[0])
;

foreach (Type entityType in entityTypes)
{
    DbSet theSet = context.Set(entityType);
    theSet.RemoveRange(theSet);
}

context.SaveChanges();




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralMessage Removed Pin
14-May-15 5:40
professionalN_tro_P14-May-15 5:40 
GeneralRe: Reflection DbSet Remove Pin
Richard Deeming14-May-15 6:30
mveRichard Deeming14-May-15 6:30 
GeneralRe: Reflection DbSet Remove Pin
Sascha Lefèvre14-May-15 8:13
professionalSascha Lefèvre14-May-15 8:13 
GeneralRe: Reflection DbSet Remove Pin
Richard Deeming14-May-15 8:39
mveRichard Deeming14-May-15 8:39 
GeneralMessage Removed Pin
18-May-15 4:42
professionalN_tro_P18-May-15 4:42 
GeneralRe: Reflection DbSet Remove Pin
Richard Deeming18-May-15 4:53
mveRichard Deeming18-May-15 4:53 
QuestionHow to play webm file in windows form application? Pin
Member 1161266213-May-15 17:59
Member 1161266213-May-15 17:59 
AnswerRe: How to play webm file in windows form application? Pin
Richard Deeming14-May-15 1:13
mveRichard Deeming14-May-15 1:13 
Questiongrouping is not working Pin
hussain54813-May-15 6:32
hussain54813-May-15 6:32 
Answer[REPOST] Pin
Sascha Lefèvre13-May-15 7:41
professionalSascha Lefèvre13-May-15 7:41 
AnswerRe: grouping is not working Pin
OriginalGriff13-May-15 8:10
mveOriginalGriff13-May-15 8:10 
QuestionShould choose ASP.NET MVC or Xamarin Pin
Ashfaque Hussain13-May-15 4:12
Ashfaque Hussain13-May-15 4:12 
GeneralRe: Should choose ASP.NET MVC or Xamarin Pin
Richard MacCutchan13-May-15 4:31
mveRichard MacCutchan13-May-15 4:31 
GeneralRe: Should choose ASP.NET MVC or Xamarin Pin
Ashfaque Hussain13-May-15 5:44
Ashfaque Hussain13-May-15 5:44 
GeneralRe: Should choose ASP.NET MVC or Xamarin Pin
Richard MacCutchan13-May-15 7:39
mveRichard MacCutchan13-May-15 7:39 
AnswerRe: Should choose ASP.NET MVC or Xamarin Pin
Hitesh Sharma _13-May-15 4:52
Hitesh Sharma _13-May-15 4:52 
GeneralRe: Should choose ASP.NET MVC or Xamarin Pin
Ashfaque Hussain13-May-15 5:45
Ashfaque Hussain13-May-15 5:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.