我正在尝试将一个通用的IRepository <>接口绑定到我的通用存储库<> - 但它总是返回null?
我尝试过各种各样的事情:
Bind(typeof(IRepository<CustomerModel>)).To(typeof(Repository<CustomerModel>));
Bind(typeof(IRepository<>)).To(typeof(Repository<>));
Run Code Online (Sandbox Code Playgroud)
但是,如果我传入非通用接口和类,那么它就像梦一样?
我试图避免使用角色提供者和成员资格提供者,因为在我看来它过于笨拙,因此我正在尝试制作我自己的"版本",它不那么笨拙,更易于管理/灵活.现在是我的问题..角色提供者有替代方案吗?(我知道我可以做自定义角色提供者,会员提供者等)
通过更易于管理/灵活,我的意思是我只能使用Roles静态类而不是直接实现到与数据库上下文交互的服务层,而是我必须使用具有自己的数据库上下文的Roles静态类等,表名也很糟糕..
提前致谢.
asp.net authentication asp.net-mvc authorization asp.net-membership
我正在尝试捕获当我将具有给定用户名的已存在用户插入我的数据库时抛出的异常.正如标题所说,我正在使用EF.当我尝试将用户插入到db时抛出的唯一异常是"UpdateException" - 如何提取此异常以识别它是重复的异常还是别的?
我正在尝试向客户提出请求,如果客户不存在,则应返回某种"未找到"页面.以下哪项是用于此类任务的最佳实践,为什么?
public ActionResult Index(int id)
{
if (customerService.GetCustomerById(id) == null)
return View("NotFound");
return View();
}
Run Code Online (Sandbox Code Playgroud)
要么
public ActionResult Index(int id)
{
if (customerService.GetCustomerById(id) == null)
throw new HttpException(404, "Customer not found");
return View();
}
Run Code Online (Sandbox Code Playgroud) 您将如何创建LINQ-TO-SQL
类型提供程序,生成或/和重新生成类?
我刚刚在我的数据库中添加了一个新表,而类型提供程序无法解决这个问题.我试图删除类型提供程序的行,并再次键入它 - 没有运气.我也试过重建......仍然没有运气.
编辑:
我已经定义了类型提供程序,如:
[<Generate>]
type dbSchema = SqlDataConnection<"conString">
Run Code Online (Sandbox Code Playgroud)
并使用它像:
let ctx = dbSchema.GetDataContext()
如果在数据库中找不到条目,则抛出异常的最佳做法是什么?
// CONTROLLER
public ActionResult Edit(int categoryId, int id)
{
Product target = Products.GetById(id);
if (target == null) throw new HttpException(404, "Product not found");
return View("Edit", target);
}
// REPOSITORY
public Product GetById(int id)
{
return context.Products.FirstOrDefault(x => x.productId == id);
}
Run Code Online (Sandbox Code Playgroud)
要么
// CONTROLLER
public ActionResult Edit(int categoryId, int id)
{
return View("Edit", Products.GetById(id));
}
// REPOSITORY
public Product GetById(int id)
{
Product target = context.Products.FirstOrDefault(x => x.productId == id);
if (target == null) throw new HttpException(404, "Product not …
Run Code Online (Sandbox Code Playgroud) 代码:
static void DoIt(string name)
{
Console.WriteLine("Hello {0} | {1}", name, Thread.CurrentThread.ManagedThreadID);
Thread.Sleep(5000);
Console.WriteLine("Bye {0} | {1}", name, Thread.CurrentThread.ManagedThreadID);
}
static void Main()
{
Task.Factory.StartNew(() => DoIt("One"));
Task.Factory.StartNew(() => DoIt("Two"));
Task.Factory.StartNew(() => DoIt("Three"));
Task.Factory.StartNew(() => DoIt("Four"));
Task.Factory.StartNew(() => DoIt("Five"));
Task.Factory.StartNew(() => DoIt("Six"));
Task.Factory.StartNew(() => DoIt("Seven"));
Task.Factory.StartNew(() => DoIt("Eight"));
Task.Factory.StartNew(() => DoIt("Nine"));
Task.Factory.StartNew(() => DoIt("Ten"));
Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)
为什么它可以立即精确启动前3个任务,但是任务4启动需要5-10秒,在任务4启动后,任务5启动前需要5-10秒,依此类推.GC是做什么的吗?有人可以澄清一下发生了什么吗?
我刚开始玩IoC容器,因此选择了Ninject.
经过几个小时的汗水和眼泪,我仍然无法弄清楚如何使用Ninject设置我的MVC3应用程序.
到目前为止,我有:
的Global.asax.cs
public class MvcApplication : Ninject.Web.Mvc.NinjectHttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
DependencyResolver.SetResolver(new MyDependencyResolver(CreateKernel()));
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
protected override IKernel CreateKernel()
{
var modules = new [] { new ServiceModule() };
return new StandardKernel(modules);
} …
Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个使用EF Code First和POCO的项目.到目前为止,我有5个POCO取决于POCO"用户".
在POCO"用户"应该是指我的现有成员关系表"aspnet_Users"(我在的DbContext的OnModelCreating方法其映射到).
问题是,我想借此优势"重新创建数据库如果模型变更"功能为斯科特谷表示在:http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development -with-entity-framework-4.aspx - 该功能基本上是在看到我的POCO中的任何更改后立即重新创建数据库.我想要它做的是重新创建数据库,但以某种方式不删除整个数据库,以便aspnet_Users仍然存在.然而,这似乎是不可能的,因为它要么创建一个全新的数据库,要么替换当前的数据库.
所以我的问题是:我注定要手动定义我的数据库表,还是我能以某种方式将我的POCO合并到我当前的数据库中,并且仍然可以使用该功能而无需全部擦除它?
嗨我已经陷入了一些与计时器相关的问题.希望有人可以帮忙..
Thread thread1 = new Thread(new ParameterizedThreadStart( execute2));
thread1.Start(externalFileParams);
Run Code Online (Sandbox Code Playgroud)
.
public void execute2(Object ob)
{
if (ob is ExternalFileParams)
{
if (boolean_variable== true)
executeMyMethod();//this also executes very well if condition is true
else
{
timer1.enabled = true;
timer1.start();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
5但是没有触发计时器的tick事件
我正在研究VS2008 3.5框架.我已经从工具箱拖动计时器并将其设置Interval
为300也试图设置Enabled
true/false方法timer1_Tick(Object sender , EventArgs e)
但是它没有被解雇
任何人都可以建议我做错了什么?