#Entity Framework Extended Library
A library the extends the functionality of Entity Framework.
##Download
The Entity Framework Extended library is available on nuget.org via package name `EntityFramework.Extended`.
To install EntityFramework.Extended, run the following command in the Package Manager Console
PM> Install-Package EntityFramework.Extended
More information about NuGet package avaliable at
https://nuget.org/packages/EntityFramework.Extended
##Development Builds
Development builds are available on the myget.org feed. A development build is promoted to the main NuGet feed when it's determined to be stable.
In your Package Manager settings add the following package source for development builds:
http://www.myget.org/F/loresoft/
##Features
- [Batch Update and Delete](https://github.com/loresoft/EntityFramework.Extended/wiki/Batch-Update-and-Delete)
- [Future Queries](https://github.com/loresoft/EntityFramework.Extended/wiki/Future-Queries)
- [Query Result Cache](https://github.com/loresoft/EntityFramework.Extended/wiki/Query-Result-Cache)
- [Audit Log](https://github.com/loresoft/EntityFramework.Extended/wiki/Audit-Log)
### Batch Update and Delete
A current limitations of the Entity Framework is that in order to update or delete an entity you have to first retrieve it into memory. Now in most scenarios this is just fine. There are however some senerios where performance would suffer. Also, for single deletes, the object must be retrieved before it can be deleted requiring two calls to the database. Batch update and delete eliminates the need to retrieve and load an entity before modifying it.
**Deleting**
//delete all users where FirstName matches
context.Users.Delete(u => u.FirstName == "firstname");
**Update**
//update all tasks with status of 1 to status of 2
context.Tasks.Update(
t => t.StatusId == 1,
t2 => new Task {StatusId = 2});
//example of using an IQueryable as the filter for the update
var users = context.Users.Where(u => u.FirstName == "firstname");
context.Users.Update(users, u => new User {FirstName = "newfirstname"});
### Future Queries
Build up a list of queries for the data that you need and the first time any of the results are accessed, all the data will retrieved in one round trip to the database server. Reducing the number of trips to the database is a great. Using this feature is as simple as appending `.Future()` to the end of your queries. To use the Future Queries, make sure to import the `EntityFramework.Extensions` namespace.
Future queries are created with the following extension methods...
- Future()
- FutureFirstOrDefault()
- FutureCount()
Sample
// build up queries
var q1 = db.Users
.Where(t => t.EmailAddress == "one@test.com")
.Future();
var q2 = db.Tasks
.Where(t => t.Summary == "Test")
.Future();
// this triggers the loading of all the future queries
var users = q1.ToList();
In the example above, there are 2 queries built up, as soon as one of the queries is enumerated, it triggers the batch load of both queries.
// base query
var q = db.Tasks.Where(t => t.Priority == 2);
// get total count
var q1 = q.FutureCount();
// get page
var q2 = q.Skip(pageIndex).Take(pageSize).Future();
// triggers execute as a batch
int total = q1.Value;
var tasks = q2.ToList();
In this example, we have a common senerio where you want to page a list of tasks. In order for the GUI to setup the paging control, you need a total count. With Future, we can batch together the queries to get all the data in one database call.
Future queries work by creating the appropriate IFutureQuery object that keeps the IQuerable. The IFutureQuery object is then stored in IFutureContext.FutureQueries list. Then, when one of the IFutureQuery objects is enumerated, it calls back to IFutureContext.ExecuteFutureQueries() via the LoadAction delegate. ExecuteFutureQueries builds a batch query from all the stored IFutureQuery objects. Finally, all the IFutureQuery objects are updated with the results from the query.
### Query Result Cache
To cache query results, use the `FromCache` extension method located in the `EntityFramework.Extensions` namespace. Below is a sample caching query results. Simply construct the LINQ query as you normally would, then append the `FromCache` extension.
//query is cached using the default settings
var tasks = db.Tasks
.Where(t => t.CompleteDate == null)
.FromCache();
//query result is now cached 300 seconds
var tasks = db.Tasks
.Where(t => t.AssignedId == myUserId && t.CompleteDate == null)
.FromCache(CachePolicy.WithDurationExpiration(TimeSpan.FromSeconds(300)));
The Query Result Cache also supports tagging the cache so you can expire common cache entries by calling `Expire` on a cache tag.
// cache assigned tasks
var tasks = db.Tasks
.Where(t => t.AssignedId == myUserId && t.CompleteDate == null)
.FromCache(tags: new[] { "Task", "Assigned-Task-" + myUserId });
// some update happened to Task, expire Task tag
CacheManager.Current.Expire("Task");
The `CacheManager` has support for providers. The default provider uses `MemoryCache` to store the cache entries. To create a custom provider, implement `ICacheProvider`. The custom provider will then need to be registered in the `Locator` container.
// Replace cache provider with Memcached provider
Locator.Current.Register<ICacheProvider>(() => new MemcachedProvider());
### Audit Log
The Audit Log feature will capture the changes to entities anytime they are submitted to the database. The Audit Log captures only the entities that are changed and only the properties on those entities that were changed. The before and after values are recorded. `AuditLogger.LastAudit` is where this information is held and there is a `ToXml()` method that makes it easy to turn the AuditLog into xml for easy storage.
The AuditLog can be customized via attributes on the entities or via a Fluent Configuration API.
Fluent Configuration
// config audit when your application is starting up...
var auditConfiguration = AuditConfiguration.Default;
auditConfiguration.IncludeRelationships = true;
auditConfiguration.LoadRelationships = true;
auditConfiguration.DefaultAuditable = true;
// customize the audit for Task entity
auditConfiguration.IsAuditable<Task>()
.NotAudited(t => t.TaskExtended)
.FormatWith(t => t.Status, v => FormatStatus(v));
// set the display member when status is a foreign key
auditConfiguration.IsAuditable<Status>()
.DisplayMember(t => t.Name);
Create an Audit Log
var db = new TrackerContext();
var audit = db.BeginAudit();
// make some updates ...
db.SaveChanges();
var log = audit.LastLog;
## License
Copyright (c) 2012, LoreSoft
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of LoreSoft nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIE
没有合适的资源?快使用搜索试试~ 我知道了~
ASPNET后台管理系统(MVC4+EF+Postsharp)源码
共1703个文件
cs:424个
png:272个
gif:181个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 61 浏览量
2022-03-17
11:26:18
上传
评论
收藏 23.5MB ZIP 举报
温馨提示
本项目基于MVC4、Entity Framework 5.0 实体框架、Autofac IOC容器、Postsharp AOP切面框架、AutoMapper 对象映射框架、javascript模块化管理框架 Seajs、DWZ UI界面框架 等 构建了一个代码结构优秀的开发框架,使得各个模块层次分明,分工明确,易于扩展,易于维护。 本系统虽然提供的是基础框架功能如:缓存、日志、用户登录登出,菜单管理,权限管理,角色管理,角色绑定权限,用户管理,用户绑定角色,拥有不同角色的用户登录后看到的界面会根据绑定的权限的不同有所不同,权限的设计精确到了一个请求,一个按钮,没有某个权限的用户是访问不了某个请求和看不到该按钮的, 正是因为基础功能牢固,并且建立的良好的编程规范和代码结构,使得按照自己的业务添加功能变得得心应手,同时本系统的源代码也具有比较好的学习价值,无论是想了解上述各个框架,还是想了解多层架构。 注意: 先运行TMall.Publish文件夹里的MigrationAppConsole生成Mysql数据库 再运行TMall.Manage
资源推荐
资源详情
资源评论
收起资源包目录
ASPNET后台管理系统(MVC4+EF+Postsharp)源码 (1703个子文件)
_._ 3B
Global.asax 111B
Global.asax 108B
DesignTimeResolveAssemblyReferences.cache 382KB
MigrationAppConsole.csprojResolveAssemblyReference.cache 238KB
ResolveAssemblyReference.cache 150KB
DesignTimeResolveAssemblyReferencesInput.cache 110KB
TMall.BizServices.csprojResolveAssemblyReference.cache 93KB
TMall.Infrastructure.Common.csprojResolveAssemblyReference.cache 68KB
DesignTimeResolveAssemblyReferencesInput.cache 34KB
DesignTimeResolveAssemblyReferencesInput.cache 9KB
DesignTimeResolveAssemblyReferencesInput.cache 9KB
DesignTimeResolveAssemblyReferencesInput.cache 8KB
DesignTimeResolveAssemblyReferencesInput.cache 8KB
DesignTimeResolveAssemblyReferencesInput.cache 8KB
DesignTimeResolveAssemblyReferencesInput.cache 8KB
DesignTimeResolveAssemblyReferencesInput.cache 7KB
DesignTimeResolveAssemblyReferencesInput.cache 7KB
DesignTimeResolveAssemblyReferencesInput.cache 7KB
DesignTimeResolveAssemblyReferencesInput.cache 7KB
DesignTimeResolveAssemblyReferencesInput.cache 7KB
DesignTimeResolveAssemblyReferencesInput.cache 7KB
DesignTimeResolveAssemblyReferencesInput.cache 7KB
DesignTimeResolveAssemblyReferencesInput.cache 7KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
MigrationAppConsole.csproj.GenerateResource.Cache 938B
Web.config 8KB
Web.config 6KB
packages.config 4KB
Web.config 3KB
packages.config 3KB
Web.config 3KB
Web.config 3KB
MigrationAppConsole.exe.config 2KB
App.config 2KB
Web.Release.config 1KB
Web.Release.config 1KB
Web.Debug.config 1KB
Web.Debug.config 1KB
Redirect.VS11.config 752B
repositories.config 507B
Redirect.config 500B
packages.config 274B
packages.config 149B
packages.config 142B
packages.config 142B
DynamicQueryable.cs 85KB
DbCommandTreeScanner.cs 25KB
AuditLogger.cs 22KB
Program.cs 21KB
CacheManager.cs 20KB
LateBinder.cs 20KB
TypeAccessor.cs 17KB
ObjectCopier.cs 17KB
GenericRepository.cs 17KB
MySqlBatchRunner.cs 16KB
InMemoryCache.cs 16KB
SqlServerBatchRunner.cs 15KB
AuditConfiguration.cs 15KB
QueryableExtensionsTest.cs 15KB
AppDomainTypeFinder.cs 14KB
ExpressionVisitor.cs 14KB
DbProviderServicesBase.cs 14KB
DbConnectionWrapper.cs 13KB
DelegateFactory.cs 12KB
IRepository.cs 12KB
BatchExtensions.cs 12KB
201307111423126_FirstMigration.cs 12KB
EntityConnectionWrapperUtils.cs 11KB
CachingAttribute.cs 11KB
MenuController.cs 11KB
EFCachingDataReaderBase.cs 10KB
ReflectionHelper.cs 10KB
PerRequestCacheManager.cs 10KB
EFCachingCommand.cs 9KB
DbProviderManifestWrapper.cs 9KB
EfRepositoryBase.cs 9KB
AccountController.cs 9KB
ContainerManager.cs 9KB
EFCachingCommandDefinition.cs 8KB
MemoryCacheProvider.cs 8KB
共 1703 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
办公模板库素材蛙
- 粉丝: 1535
- 资源: 2286
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功