Author Archives: Sava - Page 5

Генератор Южный парк

http://www.sp-studio.de/

10 качеств успешного продукта

И еще

http://mikhail.payson.ru/2012/05/10-kachestv-uspeshnogo-produkta-1.html

How to validate uploaded file in ASP.NET MVC?

Еще одна многолетняя вкладка

http://stackoverflow.com/questions/6388812/how-to-validate-uploaded-file-in-asp-net-mvc

Уроки по Asp.NET MVC

Цикл статей 2013 года

http://habrahabr.ru/post/175999/

OAuth на практике

Вкладка открыта в опере уже несколько лет. Хватит это терпеть :)

http://habrahabr.ru/post/145988/

Про MVC UI

Генерация на основе темплейтов
http://habrahabr.ru/post/165025/

JTable
http://www.jtable.org/Home/Documents
Доки
http://www.codeproject.com/Articles/277576/AJAX-based-CRUD-tables-using-ASP-NET-MVC-and-jTa#View

Подборка библиотек для таблиц

List of ASP.NET MVC grid controls

MVC Contrib
Доки http://mvccontrib.codeplex.com/wikipage?title=Grid&referringTitle=Documentation
Исходники http://mvccontrib.codeplex.com/SourceControl/latest#src/MVCContrib/UI/Grid/IGridModel.cs

Grid.Mvc
http://gridmvc.codeplex.com/

EF и Generic

Оставляю кусочек кода себе на память. Универсальный, но в моем случае требует костылей.

#region Generic
        public void CreateLang<tmodel>(TModel langModel, out IEnumerable<revisionobject> diff)
        {
            Type entityType = this.TypesModelEntity[typeof(TModel)]; //вот костыль
            var langType = this.TypesEntityLang[entityType]; //и еще один
 
            Type genericClass = typeof(EFLangRepository< ,,>);
            Type constructedClass = genericClass.MakeGenericType(typeof(TModel), entityType, langType);
 
            object repo = Activator.CreateInstance(constructedClass);
 
            diff = new List</revisionobject><revisionobject>();
            object[] args = new object[] { langModel, diff };
 
            MethodInfo magicMethod = constructedClass.GetMethod("CreateLang");
            object magicValue = magicMethod.Invoke(repo, args);
            diff = args[1] as List</revisionobject><revisionobject>;
        }
        #endregion
</revisionobject></tmodel>

Читать далее »

Фрактал

Ребилдол

Твое криминальное прошлое

Update выборочных полей в EF

http://stackoverflow.com/questions/15336248/entity-framework-5-updating-a-record

db.Users.Attach(updatedUser);
var entry = db.Entry(updatedUser);
entry.Property(e => e.Email).IsModified = true;
// other changed properties
db.SaveChanges();

Работа с полями класса

http://stackoverflow.com/questions/9210428/how-to-convert-class-into-dictionarystring-string

someObject.GetType()
     .GetProperties(BindingFlags.Instance | BindingFlags.Public)
          .ToDictionary(prop => prop.Name, prop => prop.GetValue(someObject, null))

http://stackoverflow.com/questions/4943817/mapping-object-to-dictionary-and-vice-versa/4944547#4944547

public static class ObjectExtensions
{
    public static T ToObject<T>(this IDictionary<string, object> source)
        where T : class, new()
    {
            T someObject = new T();
            Type someObjectType = someObject.GetType();
 
            foreach (KeyValuePair<string, object> item in source)
            {
                someObjectType.GetProperty(item.Key).SetValue(someObject, item.Value, null);
            }
 
            return someObject;
    }
 
    public static IDictionary<string, object> AsDictionary(this object source, BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance)
    {
        return source.GetType().GetProperties(bindingAttr).ToDictionary
        (
            propInfo => propInfo.Name,
            propInfo => propInfo.GetValue(source, null)
        );
 
    }
}
 
class A
{
    public string Prop1
    {
        get;
        set;
    }
 
    public int Prop2
    {
        get;
        set;
    }
}
 
class Program
{
    static void Main(string[] args)
    {
        Dictionary<string, object> dictionary = new Dictionary<string, object>();
        dictionary.Add("Prop1", "hello world!");
        dictionary.Add("Prop2", 3893);
        A someObject = dictionary.ToObject<A>();
 
        IDictionary<string, object> objectBackToDictionary = someObject.AsDictionary();
    }
}

http://stackoverflow.com/questions/2051834/exclude-property-from-gettype-getproperties

public class SkipPropertyAttribute : Attribute
{
}
 
public static class TypeExtensions
{
    public static PropertyInfo[] GetFilteredProperties(this Type type)
    {
        return type.GetProperties().Where(pi => pi.GetCustomAttributes(typeof(SkipPropertyAttribute), true).Length == 0).ToArray();
    }       
}
 
public class Test
{
    public string One { get; set; }
 
    [SkipProperty]
    public string Two { get; set; }
}
 
class Program
{
    static void Main(string[] args)
    {
        var t = new Test();
        Type ty = t.GetType();
 
        PropertyInfo[] pinfo = ty.GetFilteredProperties();
        foreach (PropertyInfo p in pinfo)
        {
            Console.WriteLine(p.Name);
        }
 
        Console.ReadKey();
    }
}

http://stackoverflow.com/questions/4951233/compare-two-objects-and-find-the-differences

static class extentions
{
    public static List<Variance> DetailedCompare<T>(this T val1, T val2)
    {
        List<Variance> variances = new List<Variance>();
        FieldInfo[] fi = val1.GetType().GetFields();
        foreach (FieldInfo f in fi)
        {
            Variance v = new Variance();
            v.Prop = f.Name;
            v.valA = f.GetValue(val1);
            v.valB = f.GetValue(val2);
            if (!v.valA.Equals(v.valB))
                variances.Add(v);
 
        }
        return variances;
    }
 
 
}
class Variance
{
    public string Prop { get; set; }
    public object valA { get; set; }
    public object valB { get; set; }
}

LINQ Join vs. Contains

Хозяйке на заметку.
В данном примере всё выполняется в памяти приложения.

http://stackoverflow.com/questions/16824510/select-multiple-records-based-on-list-of-ids-with-linq

Solution with .Where and .Contains has complexity of O(N square). Simple .Join should have a lot better performance (close to O(N) due to hashing). So the correct code is:

_dataContext.UserProfile.Join(idList, up => up.ID, id => id, (up, id) => up);

And now result of my measurement. I generated 100 000 UserProfiles and 100 000 ids. Join took 32ms and .Where with .Contains took 2 minutes and 19 seconds! I used pure IEnumerable for this testing to prove my statement. If you use List instead of IEnumerable, .Where and .Contains will be faster. Anyway the difference is significant. The fastest .Where .Contains is with Set<>. All it depends on complexity of underlying coletions for .Contains. Look at this post to learn about linq complexity.Look at my test sample below:

    private static void Main(string[] args)
    {
        var userProfiles = GenerateUserProfiles();
        var idList = GenerateIds();
        var stopWatch = new Stopwatch();
        stopWatch.Start();
        userProfiles.Join(idList, up => up.ID, id => id, (up, id) => up).ToArray();
        Console.WriteLine("Elapsed .Join time: {0}", stopWatch.Elapsed);
        stopWatch.Restart();
        userProfiles.Where(up => idList.Contains(up.ID)).ToArray();
        Console.WriteLine("Elapsed .Where .Contains time: {0}", stopWatch.Elapsed);
        Console.ReadLine();
    }
 
    private static IEnumerable<int> GenerateIds()
    {
       // var result = new List<int>();
        for (int i = 100000; i > 0; i--)
        {
            yield return i;
        }
    }
 
    private static IEnumerable<UserProfile> GenerateUserProfiles()
    {
        for (int i = 0; i < 100000; i++)
        {
            yield return new UserProfile {ID = i};
        }
    }

Console output:

Elapsed .Join time: 00:00:00.0322546
Elapsed .Where .Contains time: 00:02:19.4072107

А вот про SQL

http://stackoverflow.com/questions/1200295/sql-join-vs-in-performance

If the joining column is UNIQUE and marked as such, both these queries yield the same plan in SQL Server.

If it’s not, then IN is faster than JOIN on DISTINCT.

Копирасты

Итак, обычная московская квартира, 2018 год.
Читать далее »

Великие названия с минимумом креатива

Как показывает история, не всегда широкий талант копирайтера, способствовал созданию великого бренда. Иногда название пошло от фамилии или места жительства основателя.
Читать далее »

Страница 5 из 14« Первая...34567...10...Последняя »