我完全失去了 - 我有一些我甚至还不理解的超级奇怪的问题......我正在运行Entity Framework 4.1,MySql 5.xx而我的MySql Connector是v 6.4.4 - 一切正常但是每当我上传到我收到的服务器时,本地都是美丽的:
Could not load file or assembly 'MySql.Data, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileLoadException: Could not load file or assembly …Run Code Online (Sandbox Code Playgroud) mysql asp.net entity-framework mysql-connector entity-framework-4.1
我有一个非常奇怪的情况,特别是一个班级.将类添加到DbContext要插入数据库并调用Db.SaveChanges代码后,首先/ ef不会将主键id分配回类.
这真的很奇怪,我以前从未遇到过这种情况,我似乎无法在网上找到任何解决方案.
这是代码目前的样子......
发票代码头等舱
[Table("invoice")]
public class Invoice
{
[Key]
[Column("invoice_id")]
public int InvoiceId { get; set; }
[Column("invoice_credit_card_payment_id")]
public int InvoiceCreditCardPaymentId { get; set; }
[Column("batch_id")]
public int BatchId { get; set; }
[Column("customer_id")]
public int CustomerId { get; set; }
etc.....
}
Run Code Online (Sandbox Code Playgroud)
将发票插入数据库的代码
var invoice = new Invoice()
{
BatchId = 0,
Memo = "",
PayDateTime = DateTime.Now,
QuickbooksAccountName = "",
QuickbooksId = "",
Terms = "",
etc....
};
DbContext.Current.Invoices.Add(invoice);
//Invoice record does …Run Code Online (Sandbox Code Playgroud) 我无法弄清楚为什么我的属性路由不起作用.
这是我的设置:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Attribute routing
config.MapHttpAttributeRoutes();
// Convention-based routing
config.Routes.MapHttpRoute(
name: "API Default",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器与我的路由属性:
[Route("api/v1.0/orders")]
public class OrdersV1Controller
{
[APIAuthentication(RequireAuthentication = true)]
[HttpGet]
[Route("{id:int}")]
public GetOrderResponse GetOrder(int id)
{
.....
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的全局asax文件:
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
RouteConfig.RegisterRoutes(RouteTable.Routes);
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Populate;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我正在测试的URL返回404未找到:
http://localhost:60105/api/v1.0/orders/111111
不确定这是否是最佳方法,但这是我的想法
我正在使用实体框架数据模型v 4.1 - 我正在尝试动态构建一个where语句,这样我就不必每次都查询db,而是我可以构建一个"条件列表",然后一次性应用它们所以db只查询一次,而不是每次添加我的新条件 - 如果这是有道理的...
这就是我所拥有的
List<Func<Order, bool>> orderFunctions = new List<Func<Order, bool>>();
if (this.LoggedInUser.UserId == 9)
{
Func<Order, bool> deleg = o => o.Status.Equals(OrderStatus.NewOrder);
orderFunctions.Add(deleg);
}
else if (this.LoggedInUser.UserId == 22)
{
Func<Order, bool> deleg = o => o.AssignedToUserId.Equals(22);
orderFunctions.Add(deleg);
}
List<Orders> orders = Entities.Orders.Where( Some How Apply my Order Functions List Here ).ToList();
Run Code Online (Sandbox Code Playgroud)
我不确定我是否在这里采取正确的方法 - 希望这是有道理的 - 任何指导,示例代码都会很棒,我有一点时间在线查找示例/教程
我在这里找到stackoverflow上的帖子之后设置了我的DbContext模型.
这是目前的设置......
public static class DbContext
{
public static MyDbContext Db
{
get
{
if (!HttpContext.Current.Items.Contains("_db"))
{
HttpContext.Current.Items.Add("_db", new MyDbContext());
}
return HttpContext.Current.Items["_db"] as MyDbContext;
}
}
}
Run Code Online (Sandbox Code Playgroud)
上下文在end_request上的global.asax中处理,如下所示:
void Application_EndRequest(object sender, EventArgs e)
{
var db = (MyDbContext)HttpContext.Current.Items["_db"];
if (db != null)
db.Dispose();
}
Run Code Online (Sandbox Code Playgroud)
这样,在我的系统中,我可以访问Db DbContext.Db.xxxx
到目前为止,一切都在本地运行,但是,我还没有在生产环境中测试过多个用户.
我的顾虑...
我在stackoverflow上阅读了这篇文章,现在让我担心多个用户访问静态上下文可能存在数据问题.这应该关注我还是我的安装方式好吗?
我有一个Web API方法,可以获得仪表板视图.
该方法调用大约24个不同的查询.每个查询执行大约需要60ms,我正在使用Glimpse进行配置.
我希望这样做,是异步运行它们,以避免一个接一个地调用每一个,从而使它成为60ms X 5方法调用.
我也是Async Await的新手,所以我的期望可能不正确.
这是我的Web API方法
[HttpGet]
[ExceptionHandling]
public async Task<DashboardResponse> GetDashboard()
{
return await DashboardResponse.GetDashboard();
}
Run Code Online (Sandbox Code Playgroud)
这是辅助方法
public static async Task<DashboardResponse> GetDashboard()
{
var resp = new DashboardResponse();
resp.MonthGlance = await GetMonthAtAGlance();
resp.MostRecentOrder = await GetMostRecentOrder();
resp.CreateAnOrder = await GetCreateAnOrder();
resp.RecentOrders = await GetRecentOrders();
resp.RecentNotifications = await GetRecentNotifications();
var messages = MessageResponse.GetMessages(new MessageFilters() { PageNumber = 1, PageSize = 10 }).Messages;
resp.RecentMessages.Messages = messages;
resp.OrderLineChart = GetOrderLineChart();
return resp;
}
Run Code Online (Sandbox Code Playgroud)
这是辅助方法内部调用的方法之一(其余方法设置非常相似)
public static async Task<MonthGlanceResp> …Run Code Online (Sandbox Code Playgroud) c# asynchronous entity-framework async-await asp.net-web-api
我正在使用wordpress,我的一个元键值存储如下:
a:1:{i:0;s:8:"Religion";}
Run Code Online (Sandbox Code Playgroud)
我试图找出PHP中解决这个问题的最简单方法,这样我就可以以干净的方式提取"Religion"或任何元素.
希望这是有道理的 - 谢谢!
洛伦
asp.net ×5
c# ×5
async-await ×1
asynchronous ×1
dbcontext ×1
delegates ×1
linq ×1
mysql ×1
php ×1
wordpress ×1