linq,asp.net-mvc-3,viewbagRelated issues-Collection of common programming errors


  • ElHaix
    c# linq odata
    The issue started here, where I am unable to call $select or $expand on results.Given: var results = options.ApplyTo(_uow.Repository<ContentType>().Query().Get().Include(u => u.User).Where(u => u.UserId == userId).OrderBy(o => o.Description)).Cast<ContentType>().Select(x => new ContentTypeDTO(){//projection goes hereContentTypeId = x.ContentTypeId,Description = x.Description,UserDTO = new UserDTO { UserId = x.UserId,UserName = x.User.UserName}});Exception:Unable to cast t

  • I3arnon
    linq mongodb mongodb-csharp
    Here’s a JSON document where Mongo LINQ provider fails:{“results”:{“text”:”@twitterapi http://tinyurl.com/ctrefg”,”to_user_id”:396524,”to_user”:”TwitterAPI”,”from_user”:”jkoum”,”metadata”:{“result_type”:”popular”,”recent_retweets”: 109},”id”:1478555574, “from_user_id”:1833773,”iso_language_code”:”nl”,”source”:”<a href=\”http://twitter.com/\”>twitter<\/a>”,”profile_image_url”:”http://s3.amazonaws.com/twitter_production/profile_images/118412707/2522215727_a5f07da155_b_normal.jpg”,”cre

  • Simon Svensson
    c# .net visual-studio-2010 linq visual-studio-2012
    Somehow following code doesn’t compile in VS2010 but compiles in VS2012 without changes. The problematic line in VS2010 is names.Select(foo.GetName)error CS1928: ‘string[]’ does not contain a definition for ‘Select’ and the best extension method overload ‘System.Linq.Enumerable.Select<TSource,TResult>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TResult>)’ has some invalid arguments.using System; using System.Linq;namespace ConsoleApplication1 {class Pro

  • Ron Sher
    linq nhibernate spatial
    I’m starting to work with the NHibernate 3 linq provider and it’s great. Until now I’ve used NHibernate spatial with Criteria.How do I go about using linq with NHibernate spatial?Thanks, Ron

  • Matt Johnson
    c# sql-server linq entity-framework timespan
    I have the following table:SHIFT—————————————- | SHIFT_ID | SHIFT_TIME | SHIFT_DURATION | | ————————————– | | 1 | 00:00:00 | 01:00:00 | | 2 | 01:00:00 | 01:00:00 | | 3 | 02:00:00 | 01:00:00 |—————————————-Here, SHIFT_TIME and SHIFT_DURATION are of type TimeSpan.Now, when I run the following query:var query = from c in SHIFTwhere c.SHIFT_TIME + c.SHIFT_DURATION >=new TimeSp

  • cirrus
    c# linq
    Using info from various SO posts and notably this blog (corrected to use AndAlso rather than And) I’ve managed to combine similarly typed linq expressions into a single predicate. But now I want to combine two Expressions where one is an input to the other. Here’s the fully expanded original Expression;private Expression<Func<T, bool>> ExpressionIsNamed(IEnumerable<EntityName> AccessorNames){// worksExpression<Func<T, bool>> Texpr = x => x.Security.Readers.Any(n

  • afreeland
    c# linq linq-expressions
    I have a class that essentially converts a grids filter into a dynamic linq expression. The grid contains a simple search that takes a single input from user and I would like to create a contains statement that can be used as a generic search. However, I can not seem to find a way to create an Expression that I can take a decimal type and create a Contains (like) sql query.Things I have tried, but to no avail.Explicity defining as string, my intention was that I would be able to use a ‘Contains

  • BaSche
    c# linq nhibernate
    i’m facing the following situation.My objectmodel is as follows: EntityA–*>EntityB->EntityC EntityA references a List of EntityB. EntityB references a single EntityCMy mapping is:<class name=”EntityA” table=”TAB_A” ><id name=”Id” column=”A_ID” ><generator class=”native” /></id><version name=”Version” column=”VERSION” /><bag name=”listOfB” cascade=”save-update” table=”A_TO_C” lazy=”false” ><key column=”FK_A_ID” /><composite-element class=”EntityB” >

  • Rob Levine
    c# linq clr extension-methods
    A colleague has passed me an interesting code sample that crashes with an InvalidProgramException (“CLR detected an Invalid Program”) when run.The problem seems to occur at JIT time, in that this compiles fine but throws the exception just before the method with the “offending” line is called – I guess as it is being JIT’d.The line in question is calling Enumerable.ToDictionary and passing in a Func as the second argument.If the Func argument is fully specified with a lambda it works; if it is s

  • 8bitcat
    asp.net linq code-structure
    I’m pretty new to ASP.NET and I think im not using it they way it’s meant to be used with all the features packed into the latest .NET framework. I’m currently using .NET framework 4,0. There are some error in the code, don’t mind them mind they way I seem to be using ancient techniques.I have structured everything like this.I file called webservice.cs, that file is packed with webmethods like this:[WebMethod] public string laggtillprodukt(string pro1, int pro2) {int sqlstatus;string sqlinsertst

  • Davide.77
    asp.net-mvc-3 pdf fonts itextsharp font-face
    I’m not able to find a reason why my MVC 3 web site shows arabic font correctly and my pdf not.I use a bliss font in my web site;@font-face { font-family: ‘blissregular’; src: url(‘/Fonts/blissregular-webfont.eot’); src: url(‘/Fonts/blissregular-webfont.eot?#iefix’) format(’embedded-opentype’),url(‘/Fonts/blissregular-webfont.ttf’) format(‘truetype’); font-weight: normal; font-style: normal;}All working fine. After that I want to create the pdf of the output but arabic fonts does not appears.I’v

  • Jim
    asp.net asp.net-mvc asp.net-mvc-3 asynchronous
    I have a ASP.NET MVC3 application that handles time-consuming processes (copying a large file from network). What we want to do is:User clicks a button to post the form to trigger the process Application starts a new thread to start copying the file Application shows a message saying the file-copying process has begun User can close the browser while the copying processed and finished in the background.The idea is that the user doesn’t need any confirmation on the progress of the process, nor be

  • Kirk
    inversion-of-control asp.net-mvc-3
    We have recently upgraded a project to MVC 3 Tools and discovered that our inversion of control container is causing problems with the native MVC model binding validation on both client- and server-side. When we have the IoC hooked up the client validation fails to fire at all and the “IsValid” test in the controller fires erratically and passes along data when it should not. The only way we’ve been able to correct the validation framework is to disable the IoC completely. We were using Ninject

  • Cameron
    jquery asp.net-mvc-3
    I have the following JS:$(‘form’).live(‘submit’, function (event) {// Stop the form from doing a native postbackevent.preventDefault();$.ajax({type: ‘POST’,timeout: 5000,url: $(this).attr(‘action’),data: $(‘form’).serialize(),success: function (responseHtml) {$.getJSON($(this).attr(‘action’), function (data) {console.log(data);});},error: function (jqXHR, textStatus, errorThrown) {alert(‘server error’);}});});Which should log the json from the following mvc method on fail (note this is a login f

  • CD Smith
    vb.net asp.net-mvc-3 linq-to-sql .net-4.0
    I’ve read through the posts here and can’t find any eureka answers so here’s what I have. Linq to SQl not propagating a change back to the db.Here’s my code. Does anything stand out? The call to dc.GetChangeSet shows 0 changes. What am I missing? I can see the new values from “setting” being set to the cs object properties. SettingID is a primary key in my table and shows as PK in the dbml so that’s not an issue.Public Shared Function Update(ByVal setting As ClarifireSetup) As BooleanDim cs As

  • ekkis
    ajax asp.net-mvc-3 callback razor
    why do I always have so much trouble…? given that I didn’t solve the problem in my other article, I decided to just code the javascript right into the values… so I have:OnSuccess=”alert(‘ok’)”, OnFailure=”alert(‘failed’)”,so my problem is the submission works fine; a record gets inserted into the database and I get a callback… but I get the wrong callback! I get a failure even though the record got inserted. heeeeelp!

  • teahou
    asp.net-mvc-3 validation
    This has been asked and answered 100 times, and I have read them all, yet still my form submits after failing validation. I found a reference to not using jquery.validate higher than 1.9.0, so I rolled back to that (had been using 1.11) but no change.If i submit with an invalid form (nothing filled out) the error messages appear, then the form submits.I have successfully implemented validation a couple times in the past, and I can’t see what is different about this time. I need to take a break

  • Pat James
    asp.net-mvc asp.net-mvc-3 mobile 51degrees
    In my ASP.NET MVC 3 web application I am overriding the View name in a custom view engine to present a different view optimized for non-tablet mobile devices.All I want to perform this view override is an accurate value for Request.Browser.IsMobileDevice and the device’s native display width.51degrees.mobi feels very heavy and convoluted for this simple use case. Maybe that is just my frustration at trying to wade through all of the examples and documentation on the 51degrees web site to get an

  • EH_warch
    asp.net-mvc-3 sql-server-express asp.net-mvc-scaffolding
    I’m creating a new MVC 3 pilot application using Mvc3 and the MvcScaffolding NuGet, everything runs smoothly until i want to use the database i already have. The application keeps creating a database with the format:projectname.Models.projectnameContextI’m stuck in here, my connectionStrings is:<connectionStrings><add name=”ApplicationServices” connectionString=”data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true” providerNam

  • Christofer Eliasson
    c# asp.net-mvc-3 version-control entity-framework-4.3 ef-migrations
    I have an ASP.NET MVC3 project that uses Entity Framework 4.3 with the code-first approach. I use Migrations to keep the database up-to-date.The project is under source-control and I have a number of branches. What I just realized is that there will be a problem when I wan’t to merge one of my branches into the master. Since I have created migration-files in both branches, there will be overlapping migrations when I merge, which will probably cause conflicts.Is there a good way to manage Migrat

  • mattytommo
    c# asp.net-mvc performance viewbag
    When I think of a ViewBag, I associate it with the “final say.”Meaning you do all your logic and set the results to it.ViewBag.A = Some crazy math formula; ViewBag.B = Another crazy math formula; ViewBag.GrandTotal = Some crazy math formula + Another crazy math formula;This works as well:ViewBag.A = Some crazy math formula; ViewBag.B = Another crazy math formula; ViewBag.GrandTotal = ViewBag.A + ViewBag.B;Yipes, I am working with variables that formulate at runtime!Is this in anyway absurd or in

  • teresko
    asp.net-mvc razor viewbag
    For the ViewBag, I heard it was a no-no to use. I would assume have the content from the ViewBag should be incorporated into a view model?Question:Is my assumption above the best practice. (Not to use a ViewBag and second to have it in the view model) Are there situations where a ViewBag is absolutely necessary?

  • Shog9
    c# asp.net-mvc dynamic viewbag
    I am reading a book on ASP.NET MVC and I’m wondering how the following example works:Example #1Controllerpublic class MyController : Controller {public ActionResult Index(){ViewBag.MyProperty = 5;return View();} }View<h1>@ViewBag.MyProperty</h1>Now I understand that ViewBag is a dynamic object, so that’s how you can set the property (though I don’t know much about dynamic objects, never worked with them.) But how does the view get the specific instance of the ViewBag from the control

  • H.B.
    c# dynamic .net-4.0 asp.net-4.0 viewbag
    I have a situation where I would like to do something simular to what was done with the ASP.NET MVC 3 ViewBag object where properties are created at runtime? Or is it at compile time?Anyway I was wondering how to go about creating an object with this behaviour?

  • Steve Newton
    linq asp.net-mvc-3 viewbag
    Does anyone have the faintest idea what this error means please and how to resolve it? All my research is drawing a blank, I can see how to set it on MSDN but it doesn’t explain it in a way that explains to me what the issue is. If I remove some of my LINQ queries to set viewbag items then it seems to resolve it but the moment I set new ones and pass them into my view to generate a mail for MVCMailer it comes back. Not sure if its a viewbag issue or simply that I am calling too many linq quer

  • Saeed Neamati
    asp.net-mvc-3 dynamic razor null viewbag
    Consider this simple controller:Porduct product = new Product(){// Creating a product object; }; try {productManager.SaveProduct(product);return RedirectToAction(“List”); } catch (Exception ex) {ViewBag.ErrorMessage = ex.Message;return View(“Create”, product); }Now, in my Create view, I want to check ViewBag object, to see if it has Error property or not. If it has the error property, I need to inject some JavaScript into the page, to show the error message to my user.I created an extension meth

  • Amanda
    javascript mvc viewbag
    I would like to access ViewBag data from within client side code. This is what I’ve tried in my controller:ViewBag.Tasks = new JavaScriptSerializer().Serialize(tasks);In my view I would then put this in a hidden field so that it available client side:<input type=”hidden” name=”diagramData” data-nodes=”@ViewBag.Tasks” />In my Javascript file, I would then search for the info related to the selected node:alert($(“#diagramData”).data(“nodes”)); //?????The alert always shows “undefined”. W

  • CaKaL
    asp.net asp.net-mvc-3 viewbag
    var Urun = (from u in db.urunlers.Where(x => x.Yayinlama == “1”)where u.UrunID == idselect new{u.UrunID,UrunAdi= u.UrunAdi,u.UrunAciklama,u.YorumIzni}).SingleOrDefault();ViewBag.urun = Urun;This is codebehind in my “.cs” page.var Urun = ViewBag.urun; <h3 class=”Baslik”><%:Urun.UrunAdi %></h3>This is my code “.aspx” page.But i get ‘object’ does not contain a definition for ‘UrunAdi’ error?I solved my problem via another method:JavaScriptSerializer js = new JavaScriptSerialize

Web site is in building