Search Results

Search found 720 results on 29 pages for 'tolist'.

Page 11/29 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • LINQ 2 Entities , howto check DateTime.HasValue within the linq query

    - by Snoop Dogg
    Hi all ... I have this method that is supposed to get the latest messages posted, from the Table (& EntitySet) called ENTRY ///method gets "days" as parameter, used in new TimeSpan(days,0,0,0);!! using (Entities db = new Entities()) { var entries = from ent in db.ENTRY where ent.DATECREATE.Value > DateTime.Today.Subtract(new TimeSpan(days, 0, 0, 0)) select new ForumEntryGridView() { id = ent.id, baslik = ent.header, tarih = ent.entrydate.Value, membername = ent.Member.ToString() }; return entries.ToList<ForumEntryGridView>(); } Here the DATECREATED is Nullable in the database. I cant place "if"s in this query ... any way to check for that? Thx in advance

    Read the article

  • WPF: Binding Combobox in Code Behind to Property

    - by Richard
    Hi All, This might be something very straight forward and I really think it should work as is, but it doesn't... I have the following scenario: var itemSource = new Binding { Path = new PropertyPath("ItemList"), Mode = BindingMode.OneTime }; comboBox.SetBinding(ItemsControl.ItemsSourceProperty, itemSource); ItemList is simply: public IList<string> ItemList { get { return Enum.GetNames(typeof(OptionsEnum)).ToList(); } } I would have expected this to bind the list of items to the Combobox, and when I do it in XAML it works fine, but I have to do it in code behind... Any ideas?

    Read the article

  • Random sort list with LINQ and Entity Framework in vb.net

    - by Sander Versluys
    I've seen many examples in LINQ but i'm not able to reproduce the same result in vb.net. I have following code: Dim context As New MyModel.Entities() Dim rnd As New System.Random() Dim gardens As List(Of Tuin) = (From t In context.Gardens Where _ t.Approved = True And _ Not t.Famous = True _ Order By rnd.Next() _ Select t).ToList() But i receive an error when binding this list to a control. LINQ to Entities does not recognize the method 'Int32 Next()' method, and this method cannot be translated into a store expression. Any suggestion on how to get this to work?

    Read the article

  • How to create an ObservableCollection using LINQ in Silverlight

    - by sonofpirate
    In a non-Silverlight world, it is easy to use LINQ to create an ObservableCollection. This is because the ObservableCollection class has constructors that accept any IEnumerable<T or List<T. However, the Silverlight version does not! This means that code such as: var list = (from item in e.Result select new ViewModel(item)).ToList(); Items = new System.Collections.ObjectModel.ObservableCollection<ViewModel>(list); will not work in Silverlight. Is there another option to make this work besides resorting to a for-each statement?

    Read the article

  • C#: Fill DataGridView From Anonymous Linq Query

    - by mdvaldosta
    // From my form BindingSource bs = new BindingSource(); private void fillStudentGrid() { bs.DataSource = Admin.GetStudents(); dgViewStudents.DataSource = bs; } // From the Admin class public static List<Student> GetStudents() { DojoDBDataContext conn = new DojoDBDataContext(); var query = (from s in conn.Students select new Student { ID = s.ID, FirstName = s.FirstName, LastName = s.LastName, Belt = s.Belt }).ToList(); return query; } I'm trying to fill a datagridview control in Winforms, and I only want a few of the values. The code compiles, but throws a runtime error: Explicit construction of entity type 'DojoManagement.Student' in query is not allowed. Is there a way to get it working in this manner?

    Read the article

  • MVC2 Binding isn't working for Html.DropDownListFor<>

    - by devlife
    I'm trying to use the Html.DropDownListFor< HtmlHelper and am having a little trouble binding on post. The HTML renders properly but I never get a "selected" value when submitting. <%= Html.DropDownListFor( m => m.TimeZones, Model.TimeZones, new { @class = "SecureDropDown", name = "SelectedTimeZone" } ) %> [Bind(Exclude = "TimeZones")] public class SettingsViewModel : ProfileBaseModel { public IEnumerable TimeZones { get; set; } public string TimeZone { get; set; } public SettingsViewModel() { TimeZones = GetTimeZones(); TimeZone = string.Empty; } private static IEnumerable GetTimeZones() { var timeZones = TimeZoneInfo.GetSystemTimeZones().ToList(); return timeZones.Select( t = new SelectListItem { Text = t.DisplayName, Value = t.Id } ); } } I've tried a few different things and am sure I am doing something stupid... just not sure what it is :)

    Read the article

  • Outer Join is not working in Linq Query: The method 'Join' cannot follow the method 'SelectMany' or is not supported

    - by Scorpion
    I am writing the Linq query as below: But on run its throwing the following error: The method 'Join' cannot follow the method 'SelectMany' or is not supported. Try writing the query in terms of supported methods or call the 'AsEnumerable' or 'ToList' method before calling unsupported methods. LINQ from a in AccountSet join sm in new_schoolMemberSet on a.AccountId equals sm.new_OrganisationId.Id into ps from suboc in ps.DefaultIfEmpty() join sr in new_schoolRoleSet on suboc.new_SchoolRoleId.Id equals sr.new_schoolRoleId where sr.new_name == "Manager" where a.new_OrganisationType.Value == 430870007 select new { a.AccountId, a.new_OrganisationType.Value } I am expecting the result as below: I never used the Outer join in Linq before. So please correct me if I am doing it wrong. Thanks

    Read the article

  • Linq to SQL, Repository, IList and Persist All

    - by Dr. Zim
    This discusses a repository which returns IList that also uses Linq to SQL as a DAL. Once you do a .ToList(), IQueryable object is gone once you exit the Repository. This means that I need to send the objects back in to the Repo methods .Create(Model model), .Update(Model model), and .Delete(int ID). Assuming that is correct, how do you do the PersistAll()? For example, if you did the following, how would you code that in the repository? Changed a single string property in the object Called .Update(object); Changed a different string property in the object Called .Update(object); Called .PersistAll(), which would update the database with both changed strings. How would you associate the objects in the Repository parameters with the objects in the Linq to Sql data context, especially over multiple calls? I am sure this is a standard thing. Links to examples on the web would be great!

    Read the article

  • Lambda Contains in SimpleRepository.Find

    - by Anton
    In SubSonic 3.04's SimpleRepository, I cannot seem to perform a Contains operation within a lambda expression. Here's a trivial example: SimpleRepository repo = new SimpleRepository("ConnectionString"); List<int> userIds = new List<int>(); userIds.Add(1); userIds.Add(3); List<User> users = repo.Find<User>(x => userIds.Contains(x.Id)).ToList(); I get the error message: variable 'x' of type 'User' referenced from scope '', but it is not defined Am I missing something here, or does SubSonic not support Contains in lambda expressions? If not, how would this be done?

    Read the article

  • WPF: Modifying CollectionView from Dispatcher still throws errors

    - by Dusda
    I have the following bit of code that modifies an observable collection of 'screens' whenever a user leaves. void OnUserLeft(int roomId, int userId, string username) { client.ClientDispatcher.Invoke( (Action<int>)((id) => { Console.WriteLine("Hello before the storm!"); var screensToCheck = client.Screens.Where(s => s.CpuId == id).ToList(); screensToCheck.Each(s => client.Screens.Remove(s)); Console.WriteLine("Hello there!"); }), userId); } This is wrapped in a call to the client's Dispatcher, supposedly to get past the threading issues related to CollectionViews. However, I still get the following exception: This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread. The Dispatcher you see above is set in the WPF application's MainViewModel (we're using MVVM), like so: public Dispatcher ClientDispatcher { get { return Dispatcher.CurrentDispatcher; } }

    Read the article

  • InvokeMember("click") webBrowser help

    - by Tom
    I am trying to automate a web page via the weBrowser and the button that i'm trying to click has no ID only a value. here's the html code for it: Accept I can't useGetElementById as the button has no ID. If I do HtmlElement goButton = this.webBrowser1.Document.All["Accept"]; goButton.InvokeMember("click"); My script stops showing a nullreference error highlighting the "goButton.InvokeMember("click");" If I do var inputControls = (from HtmlElement element in webBrowser1.Document.GetElementsByTagName("input") select element).ToList(); HtmlElement submitButton = inputControls.First(x = x.Name == "Accept"); My script give me an "Sequence contains no matching element" error at the "HtmlElement submitButton" line and sometimes the page has more than one of these Accept buttons, so I would need to be able to tell the difference between each one as well or at least be able to click on one without the script breaking Any help with this will be greatly appreciated

    Read the article

  • ASP.NET MVC How to convert ModelState errors to json

    - by JK
    How do you get a list of all ModelState error messages? I found this code to get all the keys: ( http://stackoverflow.com/questions/888521/returning-a-list-of-keys-with-modelstate-errors) var errorKeys = (from item in ModelState where item.Value.Errors.Any() select item.Key).ToList(); But how would I get the error messages as a IList or IQueryable? I could go: foreach (var key in errorKeys) { string msg = ModelState[error].Errors[0].ErrorMessage; errorList.Add(msg); } But thats doing it manually - surely there is a way to do it using LINQ? The .ErrorMessage property is so far down the chain that I don't know how to write the LINQ...

    Read the article

  • Fill WinForms DataGridView From Anonymous Linq Query

    - by mdvaldosta
    // From my form BindingSource bs = new BindingSource(); private void fillStudentGrid() { bs.DataSource = Admin.GetStudents(); dgViewStudents.DataSource = bs; } // From the Admin class public static List<Student> GetStudents() { DojoDBDataContext conn = new DojoDBDataContext(); var query = (from s in conn.Students select new Student { ID = s.ID, FirstName = s.FirstName, LastName = s.LastName, Belt = s.Belt }).ToList(); return query; } I'm trying to fill a datagridview control in Winforms, and I only want a few of the values. The code compiles, but throws a runtime error: Explicit construction of entity type 'DojoManagement.Student' in query is not allowed. Is there a way to get it working in this manner?

    Read the article

  • How to do this in VB 2010 (C# to VB conversion)

    - by user203687
    I would like to have the following to be translated to VB 2010 (with advanced syntaxes) _domainContext.SubmitChanges( submitOperation => { _domainContext.Load<Customer>( _domainContext.GetCustomersQuery(), LoadBehavior.RefreshCurrent, loadOperation => { var results = _domainContext.Customers.Where( entity => !loadOperation.Entities.Contains(entity)).ToList(); results.ForEach( enitity => _domainContext.Customers.Detach(entity)); }, null); }, null); I managed to get the above with other ways (but not using anonymous methods). I would like to see all the advanced syntaxes available in VB 2010 to be applied to the above. Can anyone help me on this? thanks

    Read the article

  • Switching from LinqToXYZ to LinqToObjects

    - by spender
    In answering this question, it got me thinking... I often use this pattern: collectionofsomestuff //here it's LinqToEntities .Select(something=>new{something.Name,something.SomeGuid}) .ToArray() //From here on it's LinqToObjects .Select(s=>new SelectListItem() { Text = s.Name, Value = s.SomeGuid.ToString(), Selected = false }) Perhaps I'd split it over a couple of lines, but essentially, at the ToArray point, I'm effectively enumerating my query and storing the resulting sequence so that I can further process it with all the goodness of a full CLR to hand. As I have no interest in any kind of manipulation of the intermediate list, I use ToArray over ToList as there's less overhead. I do this all the time, but I wonder if there is a better pattern for this kind of problem?

    Read the article

  • Crystal report using Linq-to-sql

    - by DATT OZA
    Hello, I am bit confusing in generating crystal report from linq-to-sql object in my WpfApplication. crystalreport1 rpt = new crystalreport1(); datacontextclass1 db = new datacontextclass1(); var q = (from records in db.emp select records).toList(); rpt.setDataSource(q); crystalviewer.reportsource(rpt); I have done above steps... but its prompts error NotSupportedException Was Unhandled Dataset not support system.nullable< please help... thanx in advance..

    Read the article

  • How to log subsonic3 sql

    - by bastos.sergio
    Hi, I'm starting to develop a new asp.net application based on subsonic3 (for queries) and log4net (for logs) and would like to know how to interface subsonic3 with log4net so that log4net logs the underlying sql used by subsonic. This is what I have so far: public static IEnumerable<arma_ocorrencium> ListArmasOcorrencia() { if (logger.IsInfoEnabled) { logger.Info("ListarArmasOcorrencia: start"); } var db = new BdvdDB(); var select = from p in db.arma_ocorrencia select p; var results = select.ToList<arma_ocorrencium>(); //Execute the query here if (logger.IsInfoEnabled) { // log sql here } if (logger.IsInfoEnabled) { logger.Info("ListarArmasOcorrencia: end"); } return results; }

    Read the article

  • Consume a WebService with Integrated authentication from WPF windows application

    - by Tr1stan
    I have written a WPF windows application that consumes a .net WebService. This works fine when the web service in hosted to allow anonymous connections, however the WebService I need to consume when we go live will be held within a website that has Integrated Authentication enabled. The person running the WPF application will be logged onto a computer within the same domain as the web server and will have permission to see the WebService (without entering any auth info) if browsing to it using a web browser that is NTLM auth enabled. Is it possible to pass through the details of the already logged in user running the application to the WebService? Here is the code I'm currently using: MyWebService.SearchSoapClient client = new SearchSoapClient(); //From the research I've done I think I need to something with these: //UserName.PreAuthenticate = true; //System.Net.CredentialCache.DefaultCredentials; List<Person> result = client.FuzzySearch("This is my search string").ToList(); Any pointers much appreciated.

    Read the article

  • VB.NET GroupBy LINQ statement

    - by Jason
    I am having a bear of a time getting this to work. I have a List(Of MyItem) called Items that have a OrderId property on them. From those items, I want to create a list of Orders. Some items will have the same OrderId so I want to try to group by OrderId. I then want to sort by date. Here's what I have so far: Public ReadOnly Property AllOrders() As List(Of Order) Get Return Items.Select(Function(i As MyItem) New Order(i.OrderID)) _ .GroupBy(Function(o As Order) New Order(o.OrderID)) _ .OrderBy(Function(o As Order) o.DateOrdered).ToList End Get End Property This, of course, doesn't compile, and I get the error: Value of type 'System.Collections.Generic.List(Of System.Linq.IGrouping(Of Order, Order))' cannot be converted to 'System.Collections.Generic.List(Of Order))' I've bolded the part where I think the problem is, but I have no idea how to fix it. Also, it used to work fine (except there were duplicate values) before I added the .GroupBy statement. Anyone have any ideas? Thanks

    Read the article

  • WPF DataGrid issue with db40

    - by Rich Blumer
    I am using the following code to populate a wpf datagrid with items in my db4o OODB: IObjectContainer db = Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(), "C:\Dev\ContractKeeper\Database\ContractKeeper.yap"); var contractTypes = db.Query(typeof(ContractType)); this.dataGrid1.ItemsSource = contractTypes.ToList(); Here is the XAML: <Window x:Class="ContractKeeper.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit" Title="Window1" Height="300" Width="300"> <Grid> <dg:DataGrid AutoGenerateColumns="True" Margin="12,102,12,24" Name="dataGrid1" /> </Grid> </Window> When the items get bound to the datagrid, the gridlines appear like there are records but no data is displayed. Has anyone had this issue with db4o and the wpf datagrid?

    Read the article

  • EF 4.0 - Many to Many relationship - problem with deletes

    - by chugh97
    My Entity Model is as follows: Person , Store and PersonStores Many-to-many child table to store PeronId,StoreId When I get a person as in the code below, and try to delete all the StoreLocations, it deletes them from PersonStores as mentioned but also deletes it from the Store Table which is undesirable. Also if I have another person who has the same store Id, then it fails saying "The DELETE statement conflicted with the REFERENCE constraint \"FK_PersonStores_StoreLocations\". The conflict occurred in database \"EFMapping2\", table \"dbo.PersonStores\", column 'StoreId'.\r\nThe statement has been terminated" as it was trying to delete the StoreId but that StoreId was used for another PeronId and hence exception thrown. Person p = null; using (ClassLibrary1.Entities context = new ClassLibrary1.Entities()) { p = context.People.Where(x=> x.PersonId == 11).FirstOrDefault(); List<StoreLocation> locations = p.StoreLocations.ToList(); foreach (var item in locations) { context.Attach(item); context.DeleteObject(item); context.SaveChanges(); } }

    Read the article

  • Linq Paging - How to incorporate total record count

    - by Billy Logan
    Hello everyone, I am trying to figure out the best way of getting the record count will incorporating paging. I need this value to figure out the total page count given a page size and a few other variables. This is what i have so far which takes in the starting row and the page size using the skip and take statements. promotionInfo = (from p in matches orderby p.PROMOTION_NM descending select p).Skip(startRow).Take(pageSize).ToList(); I know i could run another query, but figured there may be another way of achieving this count without having to run the query twice. Thanks in advance, Billy

    Read the article

  • Linq2Sql relationships and WCF serialization problem

    - by devmania
    hi, here is my scenario i got Table1 id name Table2 id family fid with one to many relationship set between Table1. id and Table2.fid now here is my WCF service Code [OperationContract] public List<Table1> GetCustomers(string numberToFetch) { using (DataClassesDataContext context = new DataClassesDataContext()) { return context.Table1s.Take(int.Parse(numberToFetch)).ToList( ); } } and my ASPX page Code <body xmlns:sys="javascript:Sys" xmlns:dataview="javascript:Sys.UI.DataView"> <div id="CustomerView" class="sys-template" sys:attach="dataview" dataview:autofetch="true" dataview:dataprovider="Service2.svc" dataview:fetchParameters="{{ {numberToFetch: 2} }}" dataview:fetchoperation="GetCustomers"> <ul> <li>{{family}}</li> </ul> </div> though i set serialization mode to Unidirectional in Linq2Sql designer i am not able to get the family value and all what i get is this in firebug {"d":[{"__type":"Table1:#","id":1,"name":"asd"},{"__type":"Table1:#","id":2,"name":"wewe"}]} any help would be totally appreciated

    Read the article

  • Linq - How to query specific columns and return a lists

    - by Billy Logan
    Hello Everyone, I am trying to write a linq query that will only return certain columns from my entity object into a list object. Below is my code which produces an error(can't implicitly convert a generic list of anonymous types to a generic list of type TBLPROMOTION): List<TBLPROMOTION> promotionInfo = null; promotionInfo = (from p in matches orderby p.PROMOTION_NM descending select new { p.EFFECTIVE_DT, p.EXPIRE_DT, p.IS_ACTIVE, p.PROMOTION_DESC, p.PROMOTION_ID, p.PROMOTION_NM }).ToList(); What would be the best way to accomplish this. I do not want to do a "select p" in this case and return all the columns associated with the query. thanks in advance, Billy

    Read the article

  • How to avoid "source !=null" when using Code Contracts and Linq To Sql?

    - by Florian
    I have the following code using a normal data context which works great: var dc = new myDataContext(); Contract.Assume(dc.Cars!= null); var cars = (from c in dc.Cars where c.Owner = 'Jim' select c).ToList(); However when I convert the filter to an extension method like this: var dc = new myDataContext(); Contract.Assume(dc.Cars!= null); var cars = dc.Cars.WithOwner('Jim'); public static IQueryable<Car> WithOwner(IQueryable<Car> cars, string owner) { Contract.Requires(cars != null); return cars.Where(c => c.Owner = owner); } I get the following warning: warning : CodeContracts: requires unproven: source != null

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >