Search Results

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

Page 15/29 | < Previous Page | 11 12 13 14 15 16 17 18 19 20 21 22  | Next Page >

  • Too Many Left Outer Joins in Entity Framework 4?

    - by Adam
    I have a product entity, which has 0 or 1 "BestSeller" entities. For some reason when I say: db.Products.OrderBy(p = p.BestSeller.rating).ToList(); the SQL I get has an "extra" outer join (below). And if I add on a second 0 or 1 relation ship, and order by both, then I get 4 outer joins. It seems like each such entity is producing 2 outer joins rather than one. LINQ to SQL behaves exactly as you'd expect, with no extra join. Has anyone else experienced this, or know how to fix it? SELECT [Extent1].[id] AS [id], [Extent1].[ProductName] AS [ProductName] FROM [dbo].[Products] AS [Extent1] LEFT OUTER JOIN [dbo].[BestSeller] AS [Extent2] ON [Extent1].[id] = [Extent2].[id] LEFT OUTER JOIN [dbo].[BestSeller] AS [Extent3] ON [Extent2].[id] = [Extent3].[id] ORDER BY [Extent3].[rating] ASC

    Read the article

  • How do I add multiple joins (Fetches) to a joined table using nhibernate and LINQ ?

    - by ooo
    i have these tables /entities VacationRequestDate table which has a VacationRequestId field that links with VacationRequest table VacationRequest has PersonId and RequestStatusId fields that links with Person and RequestStatus respectively. i have this query so far: IEnumerable<VacationRequestDate> dates = Session.Query<VacationRequestDate>().Fetch(r => r.VacationRequest).ThenFetch(p=>p.RequestStatus).ToList(); this works fine and joins with VacationRequest and then VacationRequest joins with RequestStatus but i can't figure out how to add an additional EAGER join to the VacationRequest table. If i add a Fetch at the end, it refers to the VacationRequestDate table If i add a ThenFetch at the end, it refers to the RequestStatus table I can't find any api that will refer to the VacationRequest table as the reference point. how would you add multiple joins to a joined table using nhibernate LINQ ?

    Read the article

  • Asp.net razor textbox array for list items

    - by yycdev
    I can't find or figure out how to take a list of items (cupcakes) and display them in razor with a quantity field. What is happening is I am not able to get the values for each cupcake quantity in the list. Can you do textbox arrays in Razor? VIEW <div class="form-group"> <label>Cupcakes</label> @foreach (var cupcake in Model.CupcakeList) { @Html.TextBox("CupcakeQuantities", cupcake.Id) @cupcake.Name <br/> } </div> MODEL public List<Cupcake> CupcakeList { get; set; } public List<int> CupcakeQuantities { get; set; } CONTROLLER public ActionResult Create() { var model = new PartyBookingModel() { CupcakeList = db.Cupcakes.ToList(), CupcakeQuantities = new List<int>() }; return View(model); }

    Read the article

  • linq and contains

    - by kusanagi
    i have func public PageOfList<ConsaltQuestion> Filter(int? type, int pageId, EntityCollection<ConsaltCost> ConsaltRoles) { // return _dataContext.ConsaltQuestion.Where((o => o.Type == type || type == null) && (o=>o.Paid == paid)); return (from i in _dataContext.ConsaltQuestion where ((i.Type == type || type == null) && (i.Paid == true) && (ConsaltRoles.Contains(ConsaltCostDetails(i.Type.Value)))) select i).ToList().ToPageOfList(pageId, 20); } it return error LINQ to Entities does not recognize the method 'Boolean Contains(mrhome.Models.ConsaltCost)' method, and this method cannot be translated into a store expression. how can i fix it?

    Read the article

  • why doesnt' nhibernate support this syntax ??

    - by ooo
    i have the following query and its failing in Nhibernate 3 LINQ witha a "Non supported" exception. My DB tables are: VacationRequest (id, personId) VacationRequestDate (id, vacationRequestId) Person (id, FirstName, LastName) My Entities are: VacationRequest (Person, IList) VacationRequestDate (VacationRequest, Date) Here is the query that is getting a "Non supported" Exception Session.Query<VacationRequestDate>().Where(r => people.Contains(r.VacationRequest.Person, new PersonComparer())).Fetch(r=>r.VacationRequest).ToList(); is there a better way to write this that would be supported in Nhibernate? fyi . .the PersonComparer just compared person.Id

    Read the article

  • linq 'not in' query not resolving to what I expect

    - by Fiona
    I've written the following query in Linq: var res = dc.TransactionLoggings .Where( x => !dc.TrsMessages(y => y.DocId != x.DocId) ).Select(x => x.CCHMessage).ToList(); This resolves to the following: SELECT [t0].[CCHMessage] FROM [dbo].[TransactionLogging] AS [t0] WHERE NOT (EXISTS( SELECT NULL AS [EMPTY] FROM [dbo].[TrsMessages] AS [t1] WHERE [t1].[DocId] <> [t0].[DocId] )) Which always returns null Basiaclly what I'm trying to write is the following Select cchmessage from transactionlogging where docid not in (select docid from trsmessages) Any suggestions on what's wrong with my LINQ statment? Many thanks, Fiona

    Read the article

  • How to compare a string column(as DateTime) in LINQ?

    - by lyon
    I have a database with a ValidDate field - it's a string(we made a mistake, it should be a datetime, but we can't modify the database now.) and now I want to compare this filed with a parameter(validDateStart) from the website: priceList = priceList.Where(p => Convert.ToDateTime(p.ValidDate) >= Convert.ToDateTime(validDateStart)); var list = initPriceList.ToList(); But I get an error: The method ToDateTime is not implemented. Can anybody give me some help? Thanks!

    Read the article

  • In C# how can I serialize a List<int> to a byte[] in order to store it in a DB field?

    - by Matt
    In C# how can I serialize a List to a byte[] in order to store it in a DB field? I know how to serialize to a file on the disk, but how do I just serialize to a variable? Here is how I serialized to the disk: List<int> l = IenumerableofInts.ToList(); Stream s = File.OpenWrite("file.bin"); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(s, lR); s.Close(); I'm sure it's much the same but I just can't wrap my head around it.

    Read the article

  • update table with information from IDirectory

    - by sue
    I have a table with 4 columns, LoginID, LastName, FirstName, Email. The data for LoginID was populated from an other table. I have to write a small routine to update this table, by sending in the LoginID and with help of IDirectory routines, get the Lastname, firstname and email. This is what i'm attempting to do, but getting confused with the right syntax. using (TSADRequestEntities context = UnityHelper.Resolve()) { var fpvalues = context.FOCALPOINTs.ToList(); foreach (var item in fpvalues) { IEnumerable<UserInfo> query = UnityHelper.Resolve<IUserDirectory>().Search(item.LoginID); //Here, FocalPoint is the table that has the loginID and the other fields //I need to update. the query shld now hv info on lastname etc..how do I //retrieve that value and update the table? } }

    Read the article

  • Dynamic query to immediate execute?

    - by Curtis White
    I am using the MSDN Dynamic linq to sql package. It allows using strings for queries. But, the returned type is an IQueryable and not an IQueryable<T>. I do not have the ToList() method. How can I this immediate execute without manually enumerating over the IQueryable? My goal is to databind to the Selecting event on a linqtosql datasource and that throws a datacontext disposed exception. I can set the query as the Datasource on a gridview though. Any help greatly appreciated! Thanks. The dynamic linq to sql is the one from the samples that comes with visual studio.

    Read the article

  • NHibernate Linq - Duplicate Records

    - by adegiamb
    I am having a problem with duplicate blog post coming back when i run the linq statement below. The issue that a blog post can have the same tag more then once and that's causing the problem. I know when you use criteria you can do the followingcriteria.SetResultTransformer(new DistinctRootEntityResultTransformer()); How can I do the same thing with linq? List<BlogPost> result = (from blogPost in _session.Linq<BlogPost>() from tags in blogPost.Tags where tags.Tag == tag && blogPost.IsPublished && blogPost.Slug != slugToExclude orderby blogPost.DateCreated descending select blogPost).Distinct() .Skip(recordsToSkip).Take(pageSize).ToList();

    Read the article

  • Help with Linq and Generics

    - by Jonathan
    Hi to all. I'm triying to make a function that add a 'where' clause to a query based in a property and a value. This is a very simplefied version of my function. Private Function simplified(ByVal query As IQueryable(Of T), ByVal PValue As Long, ByVal p As PropertyInfo) As ObjectQuery(Of T) query = query.Where(Function(c) DirectCast(p.GetValue(c, Nothing), Long) = PValue) Dim t = query.ToList 'this line is only for testing, and here is the error raise Return query End Function The error message is: LINQ to Entities does not recognize the method 'System.Object CompareObjectEqual(System.Object, System.Object, Boolean)' method, and this method cannot be translated into a store expression. Looks like a can't use GetValue inside a linq query. Can I achieve this in other way? Post your answer in C#/VB. Chose the one that make you feel more confortable. Thanks

    Read the article

  • Linq: How to calculate the sales Total price and group them by product

    - by Daoming Yang
    I have a order list and I want to generate and rank the product with its total sales and quantity. With @tvanfosson's help, I can bring the grouped product detail with the following code, but how can I calculate and add up the total sales and quantity into each productListResult's object? Can anyone help me with this? Many thanks. var orderProductVariantListResult = productList.SelectMany(o => o.OrderProductVariantList) .Select(opv => new { Product = opv.ProductVariant.Product, Quantity = opv.Quantity, PriceSales = opv.PriceSales, Sales = opv.Quantity * opv.PriceSales, }); var productListResult = orderProductVariantResult .Select(pv => pv.Product) .GroupBy(p => p) .Select(g => new { Product = g.Key, TotalOrderCount = g.Count() }) .OrderByDescending(x => x.TotalOrderCount).ToList();

    Read the article

  • problem with dropdownlist in mvc application

    - by czuroski
    Hello, I am trying to work with an HTML.DropDownList in MVC and am not getting the expected return values. Here is my implementation for the selectList to bind to the drop down - IEnumerable<status> stat = _provider.GetAllStatuses(); Statuses = new SelectList(stat.ToList(), "id", "name", i.status.id); And here is my view - <%= Html.DropDownList("Status",Model.Statuses) %> I am getting an error when trying to run updatemodel in my controller. I then tried to individually set each object. It turns out that I am not getting a single int from the formvalue as I would expect to. Instead, I am getting a value like "5,10,2,3". I think this is coming from how I set up my selectlist, but I'm not exactly sure. Can anyone see an error in the way I am setting up this dd? Thanks for any help, and let me know if I can clarify anything.

    Read the article

  • Casting class to interface and back

    - by Thomas
    I have the following: public interface ICartItem { string Name { get; set; } } public class CartItem : ICartItem { public string Name { get; set; } } I then create a List and cast it to an interface: IList<CartItem> items = new List<CartItem>() { new CartItem() { Name = "MyItem" } }; IList<ICartItem> cartItems = items.Cast<ICartItem>().ToList(); Is there a way to cast it back again like illustrated below? IList<CartItem> newList = cartItems as IList<CartItem>;

    Read the article

  • Display xml data in silverlight datagrid, vb.net

    - by Aishwarya
    I want to display an xml file data in silverlight datagrid. im using the below code but it doesnt work.Please help. My vb.net code: Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Windows Imports System.Windows.Controls Imports System.Xml.Linq Namespace SilverlightApplication1 Public Partial Class Page Inherits UserControl Public Sub New() InitializeComponent() End Sub Private Sub Page_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) DataGrid1.ItemsSource = GetPunchReport() End Sub Public Function GetStatusReport() As List(Of Table) Dim statusReport As New List(Of Table)() Dim doc As XElement = XElement.Load("Data/PunchReport.xml") report = (From row In doc.Elements() _ Select GetStatus(row)).ToList() Return statusReport End Function Private Function GetReport(ByVal row As XElement) As Table Dim s As New Table() s.JobID= row.Attribute("JobID").Value s.VenueName= row.Attribute("VenueName").Value) Return s End Function End Class End Namespace

    Read the article

  • Eager loading in EF1.0

    - by Dave Swersky
    I have a many-to-many relationship: Application - Applications_Servers - Server This is set up in my Entity Data Model and all is well. My problem is that I'd like to eager-load the whole graph of Applications so that I have an IEnumerable<Applications>, each Application member populated with the Servers collection associated by the many-to-many relationship. Normally this wouldn't be a problem, but according to my research there must be a navigation property between Application and Server. This is not the case for me because my Applications_Servers join table has more in it than just the two keys. Therefore, there is no navigation property directly between Application and Server, and this doesn't work: var apps = (from a in context.Application.Include("Server") select a).ToList(); I get an error saying there is no navigation property on Application called "Server", and that's correct, there is none. How do I write the query to eager-load my Applications with their Servers in this case?

    Read the article

  • Get records based on child condition

    - by Shawn Mclean
    In LINQ To Entities: How do I get the records (including both child and parent) based on a condition of the child in a one to many. My structure is set up as follows: GetResources() - returns a list of Resources. GetResources().ResourceNames - this is the child, which is an entity collection. GetResources().ResourceNames - a property of one record of this child is Name. I'd like to construct something like this: return (from p in repository.GetResources() where p.ResourceNames.Exist(r => r.Name.Contains(text, StringComparison.CurrentCultureIgnoreCase)) select p).ToList(); but of course, Exist doesn't exist. thanks.

    Read the article

  • Accessing properties through Generic type parameter

    - by Veer
    I'm trying to create a generic repository for my models. Currently i've 3 different models which have no relationship between them. (Contacts, Notes, Reminders). class Repository<T> where T:class { public IQueryable<T> SearchExact(string keyword) { //Is there a way i can make the below line generic //return db.ContactModels.Where(i => i.Name == keyword) //I also tried db.GetTable<T>().Where(i => i.Name == keyword) //But the variable i doesn't have the Name property since it would know it only in the runtime //db also has a method ITable GetTable(Type modelType) but don't think if that would help me } } In MainViewModel, I call the Search method like this: Repository<ContactModel> _contactRepository = new Repository<ContactModel>(); public void Search(string keyword) { var filteredList = _contactRepository.SearchExact(keyword).ToList(); } I use Linq-To-Sql.

    Read the article

  • Subsonic 3.0 select Query using DateColumn

    - by vineth
    Hi , While selecting records using Date-Field i am facing a problem , my SQL2005 View (ViewOrders) StarDate column Have 4/23/2010 12:00:00 AM 4/23/2010 12:00:00 AM 4/23/2010 12:00:00 AM 4/23/2010 12:00:00 AM 4/23/2010 1:07:00 PM My Code using subsonic 3.0 AMDB ctx = new AMDB(); SqlQuery vwOrd = ctx.Select.From(); vwOrd = vwOrd.And("StartDate").IsGreaterThanOrEqualTo("04/22/2010");//From date vwOrd = vwOrd.And("StartDate").IsLessThanOrEqualTo("04/22/2010");// To Date List cat = vwOrd.ToList(); i can able to fetch only first four records, i can't able to fetch the final record which start date contains(4/23/2010 1:07:00 PM). I think the problem is in the time format.. How can i code in subsonic ,which compare only the date in the date-time column. I Don't need date "Between" method in subsonic, since i can get single date parameter(From date alone). how can i solve this problem. Thnks in advance

    Read the article

  • In query in Entity Frame work

    - by Syed Salman Raza Zaidi
    I am working on Entity frame work, i have created a method which is returning List of my Table, I am retrieving data on base of grpID(which is foreign key, so i can have multiple records) I have saved these grpID's in an array so I want to run IN command on Entity framework so that i can get records in single List, How can i apply In command,my code is below public List<tblResource> GetResources(long[] grpid) { try { return dataContext.tblResource.Where(c => c.GroupId == grpid && c.IsActive == true).ToList();//This code is not working as i am having array of groupIds } catch (Exception ex) { return ex; } }

    Read the article

  • Filter a List via Another

    - by user1166905
    I have a requirement to filter a list of Clients based on if they haven't had any jobs booked in the last x months. In my code I have two lists, one is my Clients and the other is a filtered List of Jobs between today and x months ago and the idea is to filter Clients based on their id not appearing in the jobs list. I tried the following: filteredClients.Where(n => jobsToSearch.Count(j => j.Client == n.ClientID) == 0).ToList(); But I seem to get ALL clients regardless. I can easily do a foreach but this severly slows down the process. How can I filter the client list based on the job list effectively?

    Read the article

  • show the list of usernames inside a div

    - by Mr_Green
    I am new to jQuery. In my project, I created one Class User in which the code is as shown below: static ConcurrentDictionary<string, User> _users = new ConcurrentDictionary<string, User>(); // // some function to add values to _users list // public List<User> GetConnectedUsers() { return _users.Values.ToList(); } I want to show this list of values in div #showUsernames. How to do this by using jQuery? I tried the below which is not showing anything /*display your contacts*/ $('#showUsernames').append(function(){ chat.server.getConnectedUsers(); }); where chat.server(signalr) calls the server-side code(Chat class).. I think the solution has nothing to do with signalr. If the above description is not enough then you can go through my code here

    Read the article

  • why LINQ 2 SQL sometime add a field like select 1 as test, others valid fields....

    - by Fredou
    I have to concat 2 linq2sql query and I have an issue since the 2 query doesn't return the same number of columns, what is weird is after a .ToList() on the queries, they can concat without problem. The reason is, for some linq2sql reason, I have 2 more column named test and test2 which come from 2 left outer join that linq2sql automatically create, something like "select 1 as test, tablefields" Is there any good reason for that? how to remove this extra "1 as test" field? here a few of examples of what it look like: google result for linq 2 sql "select 1 as test"

    Read the article

  • Linq To SQL: Retain list order when using .Contains

    - by rockinthesixstring
    I'm using Lucene.net to build a MyListOfIds As List(Of Integer) which I then pass on to my Linq service. I then search the database as follows Return _EventRepository.Read().Where(Function(e) MyListOfIds.Contains(e.ID)).ToList Now I know that Lucene is already ordering MyListOfIds based on the weight it gave each term. What sucks is that Linq is losing that order in it's SQL search. My Question: How can I retain that sort order when building my Lambda expression? I tried using LINQPad to see how the query is being built, but because I had to declare a variable LINQPad didn't show me the resultant SQL :-( Here's what I tried in LINQPad Dim i As New List(Of Integer) i.Add(1) i.Add(100) i.Add(15) i.Add(3) i.Add(123) Dim r = (From e In Events Where i.Contains(e.ID) Select e) note: my example is in VB.NET, but I don't mind if responses are in C#

    Read the article

< Previous Page | 11 12 13 14 15 16 17 18 19 20 21 22  | Next Page >