昨天我们得到了一个必须获得a类型的场景,db field并且我们必须编写该字段的描述.喜欢
Select ( Case DB_Type When 'I' Then 'Intermediate'
When 'P' Then 'Pending'
Else 'Basic'
End)
From DB_table
Run Code Online (Sandbox Code Playgroud)
我建议编写一个db函数而不是这个case语句,因为它更可重用.喜欢
Select dbo.GetTypeName(DB_Type)
from DB_table
Run Code Online (Sandbox Code Playgroud)
有趣的是,使用数据库的功能将是一个说我们的开发人员的效率低下的database functions是慢比Case statement.我通过互联网搜索找到答案,这是效率方面更好的方法但不幸的是我发现没有什么可以被认为是满意的答案.请用你的想法赐教,哪种方法更好?
我正在关注洋葱架构。并且我正在使用 ASP.NET Identity Framework。
这是我的项目结构:
1-Core
- Domain Classes //It contains my T4 template classes
-- AppUser //It is Identity User.
- Repository Interfaces
- Service Interfaces
2-Infrastructure
- Data //It contains my edmx file, I am using Db First approach.
- Dependency Injection
- Repository Interfaces Implementation
- Service Interfaces Implementation
3-WebApi
- Web Api Project
4-WebClient
- My AngularJs App
5-Test
- Test Project
Run Code Online (Sandbox Code Playgroud)
我已经复制了 ASP.NET Identity 表的脚本并在我的 SQL Server 上执行。它为我创建了身份表。
在我的Infrastructure.Data项目中,我创建了一个Edmx File …
.net asp.net onion-architecture asp.net-web-api asp.net-identity
我是新手,AngularJS并试图从中获取选定的文本和值Dropdown.我跟着很多教程仍然无法到达那里.SelectedValue并且SelectedText永远undefined.以下是我的代码:
HTML:
<div ng-app="SelectApp">
<div ng-controller="selectController">
<select name="category-group" id="categoryGroup" class="form-control" ng-model="itemSelected" ng-change="onCategoryChange(itemSelected)">
<option value="0">Select a category...</option>
<option ng-repeat="category in categories" value="{{category.id}}"
ng-disabled="category.disabled" ng-class="{'mainCategory' : category.disabled}">
{{category.name}}
</option>
</select>
</div>
Run Code Online (Sandbox Code Playgroud)
JS:
'use strict';
var app = angular.module('SelectApp', [ ]);
app.controller('selectController', ['$scope', '$window', function ($scope, $window) {
$scope.categories = [
{ id: 1, name: "- Vehicles -", disabled: true },
{ id: 2, name: "Cars" },
{ id: 3, name: "Commercial vehicles", …Run Code Online (Sandbox Code Playgroud) 我正在阅读微软关于州管理的这篇文章.
http://msdn.microsoft.com/en-us/library/75x4ha6s(v=vs.100).aspx
我在这里发现了一件有趣的事.ViewState被归类为Client Side选项(虽然我已经知道了).它让我想起了应用程序中的代码.
DataTable dt = getDatatableFromDB();
ViewState["dataTable"] = dt;
Run Code Online (Sandbox Code Playgroud)
而且这段代码目前工作正常.
我的困惑是:
我从这里使用Entity Framework Audit Trail的示例项目
问题是我们已在项目中使用.NET 4.0,但此示例使用的是.NET 4.5.
有人可以告诉我GetCustomAttribute.NET 4中的等价物,下面是我的代码:
private static string ColumnNameFactory(this Type type, string propertyName)
{
string columnName = propertyName;
Type entityType = type.GetEntityType();
var columnAttribute = entityType.GetProperty(propertyName).GetCustomAttribute<ColumnAttribute>(false);
if (columnAttribute != null && !string.IsNullOrEmpty(columnAttribute.Name))
{
columnName = columnAttribute.Name;
}
return columnName;
}
Run Code Online (Sandbox Code Playgroud)
在此代码中:GetCustomAttribute无法识别.
我陷入了一种奇怪的境地.我关注Onion Architecture,我的架构是这样的:
1-Core
- Domain Classes
- Repository Interfaces
- Service Interfaces
2-Infrastructure
- Data
- Dependency Injection // Here I am using Simple Injector as dependency injection
- Repository Interfaces Implementation
- Service Interfaces Implementation
3-WebApi
- Web Api Project
4-WebClient
- My AngularJs App
5-Test
- Test Project
Run Code Online (Sandbox Code Playgroud)
依赖注入:
[assembly: PreApplicationStartMethod(typeof(IocConfig), "RegisterDependencies")]
namespace Infrastructure.DependencyResolution
{
public class IocConfig
{
public static void RegisterDependencies()
{
var container = new Container();
container.RegisterWebApiRequest<IRepositoryAsync<Category>, Repository<Category>>();
container.RegisterWebApiRequest<ICategoryService, CategoryService>();
container.RegisterWebApiRequest<IDataContextAsync>(() => new …Run Code Online (Sandbox Code Playgroud) 目前我们正在使用Sessions在我们的页面中存储数据表,这样我们就不必再使数据库命中一次又一次地获取相同的数据表.但我担心的是它正在使用服务器内存,如果有一天大量用户登录,服务器的响应将变慢,我们的应用程序也可能崩溃.
请告诉我将数据表存储到Sessions中是一个好主意,还是应该每次从DB获取数据表?
我正在学习Jeffrey Palermo的Onion Architecture两周多了.我按照本教程创建了一个测试项目.在学习期间,我在SO上遇到了这个问题.根据公认的答案,有人nwang建议像GetProductsByCategoryId这样的方法不应该在Repository中,而另一方面则Dennis Traub
建议它是Repository的责任.我在做的是:
我有一个通用存储库Domain.Interface,我有一个方法Find:
public interface IRepository<TEntity> where TEntity : class
{
IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> filter = null);
.......
.......
.......
}
Run Code Online (Sandbox Code Playgroud)
然后,我创建了一个BaseRepository在Infrastucture.Data:
public class RepositoryBase<TEntity> : IRepository<TEntity> where TEntity : class
{
internal readonly DbSet<TEntity> dbSet;
public virtual IEnumerable<TEntity> Find(
Expression<Func<TEntity, bool>> filter = null)
{
IQueryable<TEntity> query = dbSet;
if (filter != null)
{
query = query.Where(filter);
}
return query.ToList();
} …Run Code Online (Sandbox Code Playgroud) asp.net-mvc design-patterns repository-pattern onion-architecture
我在SQL Server中有一个查询:
SELECT * FROM MyTable t
WHERE ISNULL(t.Status,'') = ''
Run Code Online (Sandbox Code Playgroud)
我如何在实体框架中做到这一点?
编辑:哦对不起,我的代码就像
WHERE ISNULL(t.Status,'') = ''
Run Code Online (Sandbox Code Playgroud) c# ×5
.net ×4
asp.net ×4
angularjs ×2
asp.net-mvc ×2
.net-4.0 ×1
datatable ×1
html ×1
isnull ×1
javascript ×1
jquery ×1
memory ×1
reflection ×1
repository ×1
session ×1
sql ×1
sql-function ×1
sql-server ×1
t-sql ×1
unit-of-work ×1
viewstate ×1