我试图过滤一些SQL服务器数据,并要求具有以下条件的结果:
有没有一种有效的方法在SQL Server中使用CHAR执行此操作,还是有人有更好的解决方案?
我目前在ASP.NET MVC 3应用程序中使用存储库模式.
我使用OutputCache通过使用类似于此的数据注释装饰我的控制器方法来减轻数据库的负载:
[OutputCache(Duration = 3600, VaryByParam = "userName")]
Run Code Online (Sandbox Code Playgroud)
最终,我想要实现的是一种缓存级别,数据被缓存直到它被更新(即它发生变化).我正在使用Entity Framework 4.1 for ORM.
使用我选择的堆栈建议的方法是什么?
asp.net-mvc caching outputcache entity-framework-4.1 asp.net-mvc-3
如何在LINQ查询中将布尔值与true和false进行比较?
如果hideCompleted为true,我想显示IsCompleted为false的值如果hideCompleted为false,我想显示IsCompleted为true或false的值
例:
(t1.IsCompleted ?? false == (hideCompleted == true ? false : (true || false)))
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个select查询,该查询返回输入日期范围介于LINQ查询中两个日期字段之间的记录.
我的意见是:
我的数据库字段是
此外,我还想确保14:00-15:00的输入不会返回15:00-16:00的值.
return (from t1 in db.Appointments where (t1.AppointmentStart <= date2 && (t1.AppointmentEnd) >= date1)
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮助我,我会很感激.
我正在寻找一种简单,可重用的方法来记录在我的.NET(MVC)项目中执行方法所花费的时间,并使用NLog记录它,并想知道是否有人对如何实现这一点有任何建议?
为了保持干净的代码和可读性,如果可能的话,我真的不想将它集成到我的代码中.
如果有人有任何建议,我很乐意听到.
我在Xcode/RestKit中编写了一个基于选项卡的应用程序,并尝试使用RKReachabilityObserver来确定设备上的Internet连接.
理想情况下,我希望在我的应用程序中有一个单一的可达性变量(如果这是可能的),但目前我的实现是按照下面的代码,并且在我的4个选项卡上复制时效果不佳.
如果有人对更好的方法有任何建议,我真的很感激你的意见.
View.h
@property (nonatomic, retain) RKReachabilityObserver *observer;
Run Code Online (Sandbox Code Playgroud)
View.m
@interface AppViewController()
{
RKReachabilityObserver *_observer;
}
@property (nonatomic) BOOL networkIsAvailable;
@synthesize observer = _observer;
-(id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
self.observer = [[RKReachabilityObserver alloc] initWithHost:@"mydomain"];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:RKReachabilityDidChangeNotification
object:_observer];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// determine network availability
if (! [_observer isReachabilityDetermined]) {
_networkIsAvailable = YES;
}
else
{
_networkIsAvailable = NO;
}
_text.returnKeyType = UIReturnKeyDone;
_text.delegate = self;
}
- …Run Code Online (Sandbox Code Playgroud) 我有一个包含查询的简单方法来计算一些值.
private decimal MyQueryBuilderMethod(List<ThingsViewModel> myThings)
{
return myThings.Where(x => x.Id == 1)
.Select(x => (x.ThisValue * x.That))
.Sum();
}
Run Code Online (Sandbox Code Playgroud)
我的目的是修改方法,允许我指定在对象中查询的x.ThisValue字段.
如果我要指定查询的Where子句,我可能会传递一个谓词,但在这种情况下,我只想改变x.ThisValue的值.
private decimal MyQueryBuilderMethod(List<ThingsViewModel> myThings, Func<ThingsViewModel,bool> predicates)
{
return myThings.Where(predicates)
.Select(x => (x.ThisValue * x.That))
.Sum();
}
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想传递类似的内容:
MyQueryBuilderMethod(things, x.ThisOtherValue)
Run Code Online (Sandbox Code Playgroud) 在ASP.NET MVC 3中使用RenderSection帮助程序时,是否可以测试是否存在提供的内容部分?
例如:
@RenderSection("RightCrumbContentArea", required: false)
Run Code Online (Sandbox Code Playgroud)
如果没有提供上述内容,我希望生成一些其他内容.
我正在寻找一些关于如何减少我的Entity Framework库对app或web.config文件的依赖性的建议.我的应用程序包含一个ADO.NET实体数据模型.
我目前在Web项目中引用了这个库,但为了做到这一点,我必须在部署之前将连接字符串添加到Web应用程序的web.config中.
我现在需要使用独立DLL,并且无法更改父项目的配置文件以包含我的EF库的配置文件.
存储我的连接字符串的最佳方法是什么,同时保持我的edmx的完整性以及我应该在哪里引用它?
在我的ASP.NET MVC应用程序中,我试图弄清楚用户是否可以访问特定的控制器,受授权数据注释的限制如下
[Authorize(Roles = "user")]
Run Code Online (Sandbox Code Playgroud)
我试图覆盖OnAuthorization以检查: -
我的用户角色存储在我创建的SessionManager对象中 - SessionManager.ActiveUser.Roles
这就是我所拥有的伪代码形式,但如果有人能帮助我做到这一点,我真的很感激.
public class HomeBaseController : Controller
{
protected override void OnAuthorization(AuthorizationContext context)
{
if (context.HttpContext.User.Identity.IsAuthenticated)
{
// these values combined are our roleName
bool isAuthorised = context.HttpContext.User.IsInRole(context.RequestContext.HttpContext.User.Identity.);
if (!context.HttpContext.User.IsInRole(---the roles associated with the requested controller action (e.g. user)---))
{
var url = new UrlHelper(context.RequestContext);
var logonUrl = url.Action("LogOn", "SSO", new { reason = "youAreAuthorisedButNotAllowedToViewThisPage" });
context.Result = new RedirectResult(logonUrl);
return;
}
}
}
Run Code Online (Sandbox Code Playgroud) c# ×4
asp.net ×3
asp.net-mvc ×3
linq ×3
.net ×1
c#-4.0 ×1
caching ×1
cocoa-touch ×1
linq-to-sql ×1
outputcache ×1
restkit ×1
sql-server ×1
t-sql ×1
xcode ×1