This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public virtual void Update(TEntity entityToUpdate) | |
{ | |
var entry = this.context.Entry(entityToUpdate); | |
var key = this.GetPrimaryKey(entry); | |
if (entry.State == EntityState.Detached) | |
{ | |
var currentEntry = this.databaseSet.Find(key); | |
if (currentEntry != null) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int GetPrimaryKey(DbEntityEntry entry) | |
{ | |
var myObject = entry.Entity; | |
var property = | |
myObject.GetType() | |
.GetProperties() | |
.FirstOrDefault(prop => Attribute.IsDefined(prop, typeof(KeyAttribute))); | |
return (int)property.GetValue(myObject, null); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var context = new YourDbContext()) | |
{ | |
context.Database.Log = Console.Write; | |
// rest of you code goes here... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var context = new YourDbContext()) | |
{ | |
context.Database.Log = message => Trace.Write(message); | |
// rest of you code goes here | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Common.Logging; | |
public class SomeClass | |
{ | |
private static readonly ILog log = LogManager.GetCurrentClassLogger(); | |
public void SomeMethod() | |
{ | |
context.Database.Log = message => log.Debug(message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Common.Logging; | |
using System.Data.Common; | |
using System.Data.Entity; | |
using System.Data.Entity.Infrastructure.Interception; | |
using System.Data.Entity.SqlServer; | |
using System.Data.SqlClient; | |
using System.Reflection; | |
using System.Linq; | |
public class CustomEFInterceptor : IDbCommandInterceptor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1. Application start up | |
protected void Application_Start() | |
{ | |
// other code ommitted | |
DbInterception.Add(new YourInterceptor()); | |
} | |
//2. DbConfiguration | |
public class YourDBContextConfiguration : DbConfiguration | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class BackgroundValueConverter : IValueConverter | |
{ | |
public object Convert(object value, Type targetType, object parameter, string language) | |
{ | |
var passwordStrength = int.Parse(value.ToString()); | |
if (passwordStrength > 33 && passwordStrength <= 66) | |
{ | |
return new SolidColorBrush(Colors.Orange); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:pd="using:TestApp.Converters" | |
mc:Ignorable="d"> | |
<!-- Other styles omitted for clarity --> | |
<pd:BackgroundValueConverter x:Key="BackgroundValueConverter"></pd:BackgroundValueConverter> | |
</ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ProgressBar Name="PrgStrength" | |
IsIndeterminate="False" | |
HorizontalAlignment="Stretch" | |
Margin="2,11,0,11" | |
Value="{Binding StrengthValue, Mode=TwoWay}" | |
Foreground="{Binding Path=StrengthValue, Converter={StaticResource BackgroundValueConverter}}" | |
Width="320"> | |
</ProgressBar> |