不要迷恋,而要实践
来源:互联网 发布:电脑软件必备 编辑:程序博客网 时间:2024/04/28 23:44
最近,在别人博客的回复上看到讨论Entity Framework性能的问题,有人不知所以人云亦云。说Entity Framework很好,甚至超越ado.net!!!
真的无言以对,对这样的老兄。只能淡淡的微笑了之,就一菜鸟!
说说自己的事,老证明不要迷恋谁,而要实践了解才是正道!
正在写MVC5+Bootstrap+postgreSQL的应用程序,本打算使用Entity Framework,但是总感觉性能差(我的观点,不知道性能问题可以不解决,对于知道的性能差绝对不用),因此使用Npgsql来直接控制数据库。问题出现了,Identity使用Entity Framework。Google了一番,终于找到方案!
在微软的网站上有单独的MySQL存储的项目源码,拿来修改成PostgreSQL数据库的。
1.使用Attribute来实现实体类与数据库之间的Insert和update的SQL语句生成,直接执行SQL即可添加和删除。
原因:为了通用允许派生IdentityUser,而增加的。
2.选择DynamicBuilder<T>作为DataReader转换为List<T>的映射方案
3.测试过其他的转换方案,包括老赵的Fasterflect和其他的库。结果如下:
第一名:老赵Fasterflect文章里面提到的Dynamic库。
第二名:老赵的Fasterflect
当然了,他们都是缓存方式。
100万次相差20毫秒左右。I3上测试的。Release模式!但是不知道为啥在家的机器上I5+8G+win7 64位上发现他们差不多了。
在编写的过程中发现如下的问题:
注册用户的时候
...
var result1 = await UserManager.CreateAsync(user, "123C567&80xx");
...
经过反编译出他的代码
public virtual async Task<IdentityResult> CreateAsync(TUser user, string password)
{
this.ThrowIfDisposed();
IUserPasswordStore<TUser, TKey> passwordStore = this.GetPasswordStore();
if (user == null)
{
throw new ArgumentNullException("user");
}
if (password == null)
{
throw new ArgumentNullException("password");
}
IdentityResult identityResult = await this.UpdatePasswordInternal(passwordStore, user, password).WithCurrentCulture<IdentityResult>();
IdentityResult result;
if (!identityResult.Succeeded)
{
result = identityResult;
}
else
{
result = await this.CreateAsync(user).WithCurrentCulture<IdentityResult>();
}
return result;
}
internal async Task<IdentityResult> UpdatePasswordInternal(IUserPasswordStore<TUser, TKey> passwordStore, TUser user, string newPassword)
{
IdentityResult identityResult = await this.PasswordValidator.ValidateAsync(newPassword).WithCurrentCulture<IdentityResult>();
IdentityResult result;
if (!identityResult.Succeeded)
{
result = identityResult;
}
else
{
await passwordStore.SetPasswordHashAsync(user, this.PasswordHasher.HashPassword(newPassword)).WithCurrentCulture();
await this.UpdateSecurityStampInternal(user).WithCurrentCulture();
result = IdentityResult.Success;
}
return result;
}
internal async Task UpdateSecurityStampInternal(TUser user)
{
if (this.SupportsUserSecurityStamp)
{
await this.GetSecurityStore().SetSecurityStampAsync(user, UserManager<TUser, TKey>.NewSecurityStamp()).WithCurrentCulture();
}
}
在SetSecurityStampAsync函数中居然调用了UserTable.Update(TUser user)方法,这就糊涂了?
明明是添加用户为啥在添加的过程中居然执行更新用户呢,这当然不能成功,多余的操作。
这是我编写自己的存储是这样!没有看Identity + Entity framework的代码。
因此不要迷恋谁,实践+学习最重要!
可能本人菜,不知道他为啥这么设计!有理解请指教!
- 不要迷恋,而要实践
- 不要迷恋哥,哥被关了!
- 不要迷恋英雄,起码自己不是
- 不要迷恋哥,哥只是个传说
- 不要迷恋哥,哥只是个传说!
- 不要迷恋哥,嫂子会揍你
- 不要迷恋哥,哥只是个传说!
- 就有过度迷恋乒乓球而每
- 迷恋。。。。
- 不要迷恋哥,嫂子会揍你!句句经典
- 转贴:不要迷恋蜂蜜,虽然它有美好的传说
- 不要迷恋乔布斯:iPod研发者才是传说
- 不要迷恋行锁,行锁只是传说
- 不要迷恋iphone7,机器人才是科技的未来!
- 成功不要“尽力”而要“借力”
- 不要事情找你,而要你找事情
- 【不要娇生惯养,而要适时鼓励】带…
- [荐] [顶] 【妙语连猪】2009经典流行话窜窜烧—(二)“不要迷恋哥!”
- 第16周上机实践项目2——用指针玩字符串(7)
- SQL编程:判断某个年份是否为闰年
- Linux串口编程
- Valid Sudoku
- iOS 学习手札
- 不要迷恋,而要实践
- 在flashdevelop中如何调用库中的元件属性
- mysql数据库设计学习---数据库设计规范化的五个要求
- Android开发 设置开机自动启动
- WINDOS 命令大全
- STM32F4固件库下载流程
- 九度OJ 1068 球的半径和体积 (模拟)
- Linux引导与初始化
- WebForm与MVC精彩评论