Archive for the ‘c#’ Category

EF Designer Code Generation Templates

Profiling Database Activity in the Entity Framework

View query generated in Linq

Posted: August 19, 2014 in c#, debug, entity framework, linq, sql
Tags: , , ,
///Code below:
var result = from x in appEntities
             where = 32
             select x;

var sql = ((System.Data.Objects.ObjectQuery)result).ToTraceString();


Other publish

    ///In filters register:
    // This method allows the client to override their browser's HTTP Accept header by putting a value in the querystring.
    GlobalConfiguration.Configuration.Filters.Add(new FormattingOverrideFilterAttribute(formatPreferenceOverride: "application/json", clearOtherPreferredMediaTypes: true));

public class FormattingOverrideFilterAttribute : ActionFilterAttribute{
    /// <summary>
    /// Allows overriding the Accept header by querystring or server preference.
    /// </summary>
    /// <param name="formatPreferenceOverride">If defined, this mime type will be injected into the Accept header of every request.</param>
    /// <param name="newQuality">Optional, The quality setting for this media type. Should be between 1 and 0.</param>
    /// <param name="clearOtherPreferredMediaTypes">If true, will remove all other media types from the Accept header.</param>
    public FormattingOverrideFilterAttribute(string formatPreferenceOverride = null, double? newQuality = null, bool clearOtherPreferredMediaTypes = false) : base() {
        NewQualityValue = newQuality;
        FormatPreferenceOverride = formatPreferenceOverride;
        ClearOtherPreferredMediaTypes = clearOtherPreferredMediaTypes;

    public double? NewQualityValue { get; set; }
    public string FormatPreferenceOverride { get; set; }
    public bool ClearOtherPreferredMediaTypes { get; set; }

    public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext) {
        var qs = actionContext.Request.RequestUri.ParseQueryString();

        var requestedMediaType = (qs["f"] ?? qs["format"] ?? FormatPreferenceOverride ?? String.Empty).ToLower();

        switch (requestedMediaType) {
            case "xml":
            case "x":
                requestedMediaType = "application/xml";
            case "j":
            case "js":
            case "json":
                requestedMediaType = "application/json";

        if (String.IsNullOrEmpty(requestedMediaType))
            return; // No action is necessary because no override was requested.

        var acceptHeaders = actionContext.Request.Headers.Accept;
        MediaTypeWithQualityHeaderValue header = null;

        if (ClearOtherPreferredMediaTypes) {
            var newAcceptHeaders = acceptHeaders.Where(h => h.MediaType == requestedMediaType || h.MediaType == "*/*").ToList();

        header = acceptHeaders.FirstOrDefault(h => h.MediaType == requestedMediaType);
        if (header == null) {
            header = new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(requestedMediaType);

        System.Diagnostics.Debug.WriteLine("Overidding HttpAccept header for format preference.");
        header.Quality = NewQualityValue;



Another…. ->

xpdflight xpdf


I create a simple converter based in hkhtmltopdf project, look more in:




Simple, reference that:


using Microsoft.AspNet.Identity;


After you can see two extensions:

//get User Id
var CurrentUserId = User.Identity.GetUserId()
//get UserName
var CurrentUserName = User.Identity.GetUserName()

Enjoy it!