获取相关实体ASP.NET WebApi OData v4导致“未找到与请求URI匹配的HTTP资源”

我按照Mike Wasson的这个asp.net教程 ,设法建立相关实体就好了,但是当我将这个逻辑应用到我的项目中时,更复杂的实体关系(其中有更多的实体关系;这是唯一的区别)在OData调用中不会成功,我得到了404这个有效负载: { “error”: { “code”: “”, “message”: “No HTTP resource was found that matches the request URI ‘http://localhost:19215/Menus(c94f7f98-6987-e411-8119-984be10349a2)/MenuPermissions’.”, “innererror”: { “message”: “No routing convention was found to select an action for the OData path with template ‘~/entityset/key/unresolved’.”, “type”: “”, “stacktrace”: “” } } } 该教程没有提到必须设置EdmModel导航,Mike Wasson指出“asp.net是官方文档:-)”; 所以,我花了一些时间试图让这些相关的实体工作,以为我错误地设置了项目。 我认为它可能与NuGet正在安装的ASP.NET OData库版本有关(NuGet Console安装6.9.x,而NuGet Dialog安装6.5.x)。 我也想知道是不是因为我将项目设置为一个完全空的项目然后使用OWIN,所以我尝试使用纯ASP.NET模板化解决方案。 我还尝试了一些其他可能的解决方案:我的控制器方法上的OData-route-attributes; […]

基于百分比的概率

我有这段代码: Random rand = new Random(); int chance = rand.Next(1, 101); if (chance <= 25) // probability of 25% { Console.WriteLine("You win"); } else { Console.WriteLine("You lose"); } 我的问题是,它真的计算出25%的获胜概率吗? 在这里赢球的机会是25%? 编辑: 我刚刚写了这个: double total = 0; double prob = 0; Random rnd = new Random(); for (int i = 0; i < 100; i++) { […]

使用LINQ进行动态表达。 如何找到厨房?

我尝试实现用户动态filter,其中使用选择一些属性,选择一些运算符并选择值。 由于我没有找到这个问题的答案,我尝试使用LINQ表达式。 主要是我需要确定主要房间是厨房的所有房屋(任何感觉,我知道)。 using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; //using System.Linq.Dynamic; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { Room aRoom = new Room() { Name = “a Room” }; Room bRoom = new Room() { Name = “b Room” }; Room cRoom = new Room() { Name = “c […]

嵌套LINQ返回此方法无法转换为存储表达式exception

以下LINQ: retval = ( from jm in entities.JobMasters where jm.UserId == userId && jm.IsRemote == false select new JobDto { JobMasterId = jm.JobMasterId, ExternalTaskId = jm.ExternalTaskId, JobDetails = ( from jd in entities.JobDetails where jd.JobMasterId == jm.JobMasterId select new JobDetailDto { ScreenFieldId = jd.ScreenFieldId, FieldValue = jd.FieldValue } ).ToList() } ).ToList(); 给我这个错误: LINQ to Entities无法识别方法’System.Collections.Generic.List`1 […]

以编程方式将列添加到WPF中的listview?

如何以编程方式将列添加到列表视图?

使用defaultValue时,如何在Entity框架中获取插入实体的Id?

有没有办法使用defaultValue发送属性但是用数据库计算结果更新它? 数据库中有一个触发器,对于输入-1,触发一个计算新值的过程。 如何获得价值? var x = new Stuff(); db.Stuff.AddObject(x); db.SaveChanges(); return x.ID //gives -1, but the computed value should be different.

如何强制Task.Factory.StartNew到后台线程?

我已经看到了许多与此相似的其他问题,但在那里找不到我的答案。 我的问题是我用以下流程创建线程: private void btn_Click(object sender, EventArgs e) { service.GetCount( (count, ex) => { if (ex != null) return; for (int i = 0; i < count; i++) { service.Get(onItemReceived, i); } } ); } public void GetCount(Action callback) { var callingThread = TaskScheduler.FromCurrentSynchronizationContext(); Func action = () => { return client.GetCount(); // Synchronous method, […]

取消任务

如果等待时间结束,我有一个需要取消的任务。 例如 var t = Task.Factory.StartNew(() => { Thread.Sleep(5000) // some long running task “do something” }); Task.WaitAll(new[] {t}, 1000); 但似乎任务仍在继续。 我尝试使用CancellationTokenSource,但似乎也没有用。 我使用以下代码段确认了这一点 static void Main(string[] args) { var cancellationTokenSource = new CancellationTokenSource(); var t = Task.Factory.StartNew(() => { Thread.Sleep(5000); Console.WriteLine(“Still working”); }, cancellationTokenSource.Token); Task.WaitAll(new[] {t}, 1000); cancellationTokenSource.Cancel(); Console.ReadLine(); } 控制台显示“仍在工作”。 我以为任务会被取消。 我相信我错过了一些东西。 我错过了什么? 谢谢。

Uri.IsWellFormedUriString需要更新吗?

我想我可能在Uri.IsWellFormedUriString方法中发现了一个错误,可能是因为它只符合RFC 2396和RFC 2732标准,而不是新的RFC 3986 ,这使得前面提到的两个过时了。 我认为发生的是任何非us-ascii字符都会导致失败,因此其中包含æ,ø,ö或å等字符的url会使其返回false。 由于现在允许这些字符( 维基百科等人使用它们),我认为Uri.IsWellFormedUriString应该接受它们。 下面的正则表达式取自RFC 3986。 你怎么看? Uri课程应该更新吗? 无论如何这里是一些显示错误的示例代码: static void Main(string[] args) { var urls = new [] { @”/aaa/bbb/cccd”, @”/aaa/bbb/cccæ”, @”/aaa/bbb/cccø”, @”/aaa/bbb/cccå” }; var regex = new Regex(@”^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?”); Debug.WriteLine(“”); foreach (var url in urls) { if (Uri.IsWellFormedUriString(url, UriKind.Relative)) Debug.WriteLine(url + ” is a wellformed Uri”); if (regex.IsMatch(url)) Debug.WriteLine(url + […]

流zip文件MVC.NET开始流式传输

我正在尝试创建一种方法,在用户下载时不断地传输zip文件(这样就不会浪费流媒体) 我添加了一个thread.sleep来模拟延迟 public override void ExecuteResult(ControllerContext context) { HttpResponseBase response = context.HttpContext.Response; response.Clear(); response.ClearContent(); response.ClearHeaders(); response.Cookies.Clear(); response.ContentType = ContentType; response.ContentEncoding = Encoding.Default; response.AddHeader(“Content-Type”, ContentType); context.HttpContext.Response.AddHeader(“Content-Disposition”, String.Format(“attachment; filename={0}”, this.DownloadName)); int ind = 0; using (ZipOutputStream zipOStream = new ZipOutputStream(context.HttpContext.Response.OutputStream)) { foreach (var file in FilesToZip) { ZipEntry entry = new ZipEntry(FilesToZipNames[ind++]); zipOStream.PutNextEntry(entry); Thread.Sleep(1000); zipOStream.Write(file, 0, file.Length); […]