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
Image image = new Bitmap(1,1); | |
MemoryStream ms = new MemoryStream(); | |
image.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp); | |
var test = ms.ToArray(); |
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 TResult CallWebApi<TResult, TRequest>(string baseURI, string resource, string method, TRequest request) | |
{ | |
HttpClient client = new HttpClient(); | |
client.BaseAddress = new Uri(baseURI); | |
// Add an Accept header for JSON format. | |
client.DefaultRequestHeaders.Accept.Add( | |
new MediaTypeWithQualityHeaderValue("application/json")); |
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 class Source | |
{ | |
public string FullName { get; set; } | |
public int NumberOfYears { get; set; } | |
} | |
public class Destination | |
{ | |
[Key] | |
public int UserId { get; set; } | |
public string Name { get; set; } |
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 interface IRepository<T> | |
{ | |
void Add(T obj); | |
IQueryable<T> Find(Expression<Func<T, bool>> predicate); | |
} |
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 interface IRepository<TI, TO> | |
{ | |
void Add(TI obj); | |
IQueryable<TO> Find(Expression<Func<TI, bool>> predicate); | |
} |
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 void Add(Source source) | |
{ | |
_context.Users.Add(Mapper.Map<Destination>(source)); | |
} |
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
class ParameterReplacer : ExpressionVisitor | |
{ | |
private readonly ParameterExpression _parameter; | |
private readonly Expression _replacement; | |
private ParameterReplacer(ParameterExpression parameter, Expression replacement) | |
{ | |
_parameter = parameter; | |
_replacement = replacement; | |
} |
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 static class FunctionCompositionExtensions | |
{ | |
public static Expression<Func<TX, TY>> Compose<TX, TY, TZ>(this Expression<Func<TZ, TY>> outer, Expression<Func<TX, TZ>> inner) | |
{ | |
return Expression.Lambda<Func<TX, TY>>( | |
ParameterReplacer.Replace(outer.Body, outer.Parameters[0], inner.Body), | |
inner.Parameters[0]); | |
} | |
} |
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 class SourceRepositorySql : IRepository<Source, Destination>, IDisposable | |
{ | |
private readonly MyContext _context; | |
public SourceRepositorySql(MyContext context) | |
{ | |
_context = context; | |
} | |
public void Add(Source source) |
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
[Fact] | |
[UseDatabase] | |
public void ShouldConvertPredicates() | |
{ | |
var connStr = ConfigurationManager.ConnectionStrings["SQLExpressConnection"].ConnectionString; | |
var myContext = new MyContext(connStr); | |
using (var repository = new SourceRepositorySql(myContext)) | |
{ | |
AddRecords(repository); |
OlderNewer