Search Results

Search found 9232 results on 370 pages for 'linq tutorial'.

Page 29/370 | < Previous Page | 25 26 27 28 29 30 31 32 33 34 35 36  | Next Page >

  • Databind gridview with LINQ

    - by Anders Svensson
    I have two database tables, one for Users of a web site, containing the fields "UserID", "Name" and the foreign key "PageID". And the other with the fields "PageID" (here the primary key), and "Url". I want to be able to show the data in a gridview with data from both tables, and I'd like to do it with databinding in the aspx page. I'm not sure how to do this, though, and I can't find any good examples of this particular situation. Here's what I have so far: <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="LinqBinding._Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <h2> Testing LINQ </h2> <asp:GridView ID="GridView1" runat="server" DataSourceID="LinqDataSourceUsers" AutoGenerateColumns="false"> <Columns> <asp:CommandField ShowSelectButton="True" /> <asp:BoundField DataField="UserID" HeaderText="UserID" /> <asp:BoundField DataField="Name" HeaderText="Name" /> <asp:BoundField DataField="PageID" HeaderText="PageID" /> <asp:TemplateField HeaderText="Pages"> <ItemTemplate <asp:DropDownList ID="DropDownList1" DataSourceID="LinqDataSourcePages" SelectedValue='<%#Bind("PageID") %>' DataTextField="Url" DataValueField="PageID" runat="server"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:LinqDataSource ID="LinqDataSourcePages" runat="server" ContextTypeName="LinqBinding.UserDataContext" EntityTypeName="" TableName="Pages"> </asp:LinqDataSource> <asp:LinqDataSource ID="LinqDataSourceUsers" runat="server" ContextTypeName="LinqBinding.UserDataContext" EntityTypeName="" TableName="Users"> </asp:LinqDataSource> </asp:Content> But this only works in so far as it gets the user table into the gridview (that's not a problem), and I get the page data into the dropdown, but here's the problem: I of course get ALL the page data in there, not just the pages for each user on each row. So how do I put some sort of "where" constraint on dropdown for each row to only show the pages for the user in that row? (Also, to be honest I'm not sure I'm getting the foreign key relationship right, because I'm not too used to working with relationships). EDIT: I think I have set up the relationship incorrectly. I keep getting the message that "Pages" doesn't exist as a property on the User object. And I guess it can't since the relationship right now is one way. So I tried to create a many-to-many relationship. Again, my database knowledge is a bit limited, but I added a so called "junction table" with the fields UserID and PageID, same as the other tables' primary keys. I wasn't able to make both of these primary keys in the junction table though (which it looked like some people had in examples I've seen...but since it wasn't possible I guessed they shouldn't be). Anyway, I created a relationship from each table and created new LINQ classes from that. But then what do I do? I set the junction table as the Linq data source, since I guessed I had to do this to access both tables, but that doesn't work. Then it complains there is no Name property on that object. So how do I access the related tables? Here's what I have now with the many-to-many relationship: <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ManyToMany._Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <h2> Many to many LINQ </h2> <asp:GridView ID="GridView1" runat="server" DataSourceID="LinqDataSource1" AutoGenerateColumns="false"> <Columns> <asp:CommandField ShowSelectButton="True" /> <asp:BoundField DataField="UserID" HeaderText="UserID" /> <asp:BoundField DataField="Name" HeaderText="Name" /> <asp:BoundField DataField="PageID" HeaderText="PageID" /> <asp:TemplateField HeaderText="Pages"> <ItemTemplate> <asp:DropDownList ID="DropDownList1" DataSource='<%#Eval("Pages") %>' SelectedValue='<%#Bind("PageID") %>' DataTextField="Url" DataValueField="PageID" runat="server"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="ManyToMany.UserPageDataContext" EntityTypeName="" TableName="UserPages"> </asp:LinqDataSource> </asp:Content>

    Read the article

  • SqlDateTime overflow on INSERT when date is correct using a Linq to SQL DataContext

    - by Jan Hoefnagels
    Dear Linq experts, I get an SqlDateTime overflow error (Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.) when doing an INSERT using an Linq DataContext connected to SQL Server database when I do the SubmitChanges(). When I use the debugger the date value is correct. Even if I temporary update the code to set the date value to DateTime.Now it will not do the insert. Did anybody found a work-around for this behaviour? Maybe there is a way to check what SQL the datacontext submits to the database.

    Read the article

  • How to check if object is sql to linq type

    - by remdao
    Hi, anyone know if there's any easy way to check if an object is an sql to ling type? I have a method like this but would like it to only accept valid types. public static void Update(params object[] items) { using (TheDataContext dc = new TheDataContext()) { System.Data.Linq.ITable table; if(items.Length > 0) table = dc.GetTable(items[0].GetType()); for (int i = 0; i < items.Length; i++) { table.Attach(items[i]); dc.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, items[i]); } dc.SubmitChanges(); } }

    Read the article

  • The specified type member 'EntityKey' is not supported in LINQ to Entities

    - by user300992
    I have 2 Entities "UserProfile" and "Agent", they are 1-many relationship. I want to do a query to get a list of Agents by giving the userProfileEntityKey. When I run it, I got this "The specified type member 'EntityKey' is not supported in LINQ to Entities" error. public IQueryable<Agent> GetAgentListByUserProfile(EntityKey userProfileEntityKey) { ObjectQuery<Agent> agentObjects = this.DataContext.AgentSet; IQueryable<Agent> resultQuery = (from p in agentObjects where p.UserProfile.EntityKey == userProfileEntityKey select p); return resultQuery; } So, what is the correct way to do this? Do I use p.UserProfile.UserId = UserId ? If that's the case, it's not conceptual anymore. Or should I write object query instead of LINQ query?

    Read the article

  • Getting an XML node using LINQ

    - by MarceloRamires
    Somehow, using linq I can't test it with this CUF field in the beginning: <NFe> <infNFe versao="1.0" Id="NFe0000000000"> <ide> <cUF>35</cUF> <!--...--> </ide> </NFe> With the following code: XDocument document = XDocument.Load(@"c:\nota.xml"); var query = from NFe in document.Descendants("NFe") select new { cuf = NFe.Element("infNFe").Element("ide").Element("cUF").Value }; The whole XML loads into document (checked) but NFe.cuf gives me nothing. I guess the parameters inside the nodes are messing it up.. How do I get this "cuf" with linq? What if I wanted the Id parameter in infNFe ?

    Read the article

  • Efficient Search function with Linq to SQL

    - by Bayonian
    Hi, I'm using VB.NET and Linq to SQL. I have a table with thousands of rows and growing. Right now I'm using .Contains() in the Where clause to perform the query. Below is my search function : Public Shared Function DemoSearchFunction(ByVal keyword As String) As DataTable Dim db As New BibleDataClassesDataContext() Dim query = From b In db.khmer_books _ From ch In db.khmer_chapters _ From v In db.testing_khmers _ Where v.t_v.Contains(keyword) And ch.kh_book_id = b.kh_b_id And v.t_chid = ch.kh_ch_id _ Select b.kh_b_id, b.kh_b_title, ch.kh_ch_id, ch.kh_ch_number, v.t_id, v.t_vn, v.t_v Dim dtDataTableOne = New DataTable("dtOne") dtDataTableOne.Columns.Add("bid", GetType(Integer)) dtDataTableOne.Columns.Add("btitle", GetType(String)) dtDataTableOne.Columns.Add("chid", GetType(Integer)) dtDataTableOne.Columns.Add("chn", GetType(Integer)) dtDataTableOne.Columns.Add("vid", GetType(Integer)) dtDataTableOne.Columns.Add("vn", GetType(Integer)) dtDataTableOne.Columns.Add("verse", GetType(String)) For Each r In query dtDataTableOne.Rows.Add(New Object() {r.kh_b_id, r.kh_b_title, r.kh_ch_id, r.kh_ch_number, r.t_id, r.t_vn, r.t_v}) Next Return dtDataTableOne End Function I would like to know other methods for doing efficient search using Linq to SQL. Thanks.

    Read the article

  • Properties.Settings Ambiguity after adding LINQ to SQL

    - by Emmanuel Smith
    I have recently linked a database to my C# service by creating a LINQ to SQL item in my solution. Everything was fine and dandy as I was continuing to code, but then I suddenly noticed that there where 16 Ambiguity errors. e.g. Ambiguity between 'EmailService.Properties.Settings.defaultInstance' and 'EmailService.Properties.Settings.defaultInstance' What happened was that the database file decided to create it's own Setting.Designer.cs; So now I have a Settings.Designer.cs and a Settings1.Designer.cs (which was created by the LINQ to SQL file) in my Properties folder. Is there anyway that I can change where the database file is referencing its settings so I can delete the duplicate?

    Read the article

  • Simple Linq Dynamic Query question

    - by Dr. Zim
    In Linq Dynamic Query, Scott Guthrie shows an example Linq query: var query = db.Customers. Where("City == @0 and Orders.Count >= @1", "London", 10). OrderBy("CompanyName"). Select("new( CompanyName as Name, Phone)"); Notice the projection new( CompanyName as Name, Phone). If I have a class like this: public class CompanyContact { public string Name {get;set;} public string Phone {get;set;} } How could I essentially "cast" his result using the CompanyContact data type without doing a foreach on each record and dumping it in to a different data structure? To my knowledge the only .Select available is the Dymanic Query version which only takes a string and parameter list.

    Read the article

  • To call SelectMany dynamically in the way of System.Linq.Dynamic

    - by user341127
    In System.Linq.Dynamic, there are a few methods to form Select, Where and other Linq statements dynamically. But there is no for SelectMany. The method for Select is as the following: public static IQueryable Select(this IQueryable source, string selector, params object[] values) { if (source == null) throw new ArgumentNullException("source"); if (selector == null) throw new ArgumentNullException("selector"); LambdaExpression lambda = DynamicExpression.ParseLambda(source.ElementType, null, selector, values); IQueryable result = source.Provider.CreateQuery( Expression.Call( typeof(Queryable), "Select", new Type[] { source.ElementType, lambda.Body.Type }, source.Expression, Expression.Quote(lambda))); return result; } I tried to modify the above code, after hours working, I couldn't find a way out. Any suggestions are welcome. Ying

    Read the article

  • Override default operations order in LINQ

    - by Erick
    For one of our applications we do use LINQ to update a few reccords of the database. For business reasons we do require that only one item of a list to be primary. When we designed we decided to fire all of queries at the database at once. The problems occurs when we add one row and update the primary element to be the second item. See, the default behavior for order of operations with LINQ is to Insert, Update, Delete. If I Insert a first element I get a check constraint error with SQL Server. The best in my opinion would be to override and make sure to Update before Insert, this way we make sure that check constraints are kept. Tho there is not a lot of documentation on the mather. Any idea ?

    Read the article

  • C# Linq Entity Conversion Error on Nonexistent Value?

    - by Ryan
    While trying to query some data using the Linq Entity Framework I'm receiving the following exception: {"Conversion failed when converting the varchar value '3208,7' to data type int."} The thing that is confusing is that this value does not even exist in the view I am querying from. It does exist in the table the view is based on, however. The query I'm running is the following: return context.vb_audit_department .Where(x => x.department_id == department_id && x.version_id == version_id) .GroupBy(x => new { x.action_date, x.change_type, x.user_ntid, x.label }) .Select(x => new { action_date = x.Key.action_date, change_type = x.Key.change_type, user_ntid = x.Key.user_ntid, label = x.Key.label, count = x.Count(), items = x }) .OrderByDescending(x => x.action_date) .Skip(startRowIndex) .Take(maximumRows) .ToList(); Can somebody explain why LINQ queries the underlying table instead of the actual view, and if there is any way around this behavior?

    Read the article

  • Nullable Integer ? (working with linq)

    - by nCdy
    I've got exception about convert NULL to Int32. I've got a table from database with nullable tinyint [Column(Storage="_StatType", DbType="tinyint NULL")] public StatType : int { get { _StatType; } } (to get C# code just replace variable's type) and after making linq select def StartLinq = linq <#from lpi in _CfgListParIzm where lpi.ID_ListParIzm==drr1 select (lpi.StatType) #> ; StartLinq.ToArray()[0] can't be readed if that is null :-/ mutable STT : int = 0; try { _=int.TryParse(StartLinq.ToArray()[0].ToString(), out STT); } catch { | _ is Exception => () /* I don't care*/ } upper code is very poor trick :( I wont use it.

    Read the article

  • linq to sql dynamic data modify object before insert and update

    - by Dan Tanner
    I'm using Dynamic Data and LINQ to SQL for some admin pages on a .NET 3.5 web app. All my admin tables a CreatedBy, CreatedDate, UpdatedBy, and UpdatedDate. I'm looking for a way to inject the setting of these properties before the objects are inserted and updated. I've seen an object_inserting hook if you have a linq to sql datasource in the web form, but I'm using dynamic data...is there an easy way to generically set that? And I've also looked at modifying each of the partial classes for my admin objects, but the closest hook I see is to implement the OnValidate method with the Insert action. Any suggestions? TIA.

    Read the article

  • linq hierarchy problem

    - by Pratik
    I reterive a result from sql server as ProjectDetailID,ProjectID,ParentID,...,C1,C2,C3,... where C1 implies(=) companyOne, C2=CompanyTwo ... etc and dynamically can have 'n' companies For time being lets consider only 3 companies, So I get : ProjectDetailID,ProjectID,ParentID,C1,C2,C3 10,1,0,NULL,NULL,NULL 10,2,1,NULL,NULL,NULL 10,3,2,90,NULL,NULL 10,4,2,NULL,60,NULL 10,10,1,70,NULL,NULL 10,5,10,20,40,NULL 10,13,2,NULL,NULL,NULL I want from this following result using LINQ (C#) ProjectDetailID,ProjectID,ParentID,C1,C2,C3 10,1,0,180,100,NULL 10,2,1,90,60,NULL 10,3,2,90,NULL,NULL 10,4,2,NULL,60,NULL 10,10,1,90,40,NULL 10,5,10,20,40,NULL 10,13,2,NULL,NULL,NULL The problem is that at parent level i have null value for a company but at its child i have some value, which i keep on adding and have placed that in parent corresponding to that company only. I am not getting from where to start. Please share your ideas. And i am looking to do this in LINQ using C#

    Read the article

  • LINQ to SQL SubmitChangess() progress

    - by Emir
    I'm using LINQ to SQLto import old DBF files into MSSQL. I'm reading all rows and adding them to database using ctx.MyTable.InsertOnSubmit(row) After reading phase is completed I have around 100 000 pending inserts. ctx.SubmitChanges() naturally is taking a long time. Is there any way to track progress of the ctx.submitchanges()? Can ctx.Log somehow be used for this purpose? Update: Is it possible to use ctx.GetChangeSet().Inserts.Count and track insert statements using the Log? Dividing ctx.SubmitChanges() into smaller chunks is not working for me, because I need transaction, all or nothing. Update 2: I've found nice class ActionTextWriter using which I will try to count inserts. http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers

    Read the article

  • LINQ query and lambda expressions

    - by user329269
    I'm trying to write a LINQ query and am having problems. I'm not sure if lambda expressions are the answer or not but I think they may be. I have two combo boxes on my form: "State" and "Color". I want to select Widgets from my database based on the values of these two dropdowns. My widgets can be in one of the following states: Not Started, In Production, In Finishing, In Inventory, Sold. Widgets can have any color in the 'color' table in the database. The 'state' combobox has selections "Not Sold," "In Production/Finishing", "Not Started," "In Production," "In Finishing," "In Inventory," "Sold." (I hope these are self-explanatory.) The 'color' dropdown has "All Colors," and a separate item for each color in the database. How can I create a LINQ query to select the widgets I want from the database based on the dropdowns?

    Read the article

  • Using one LINQ statement with different parameters

    - by Brettski
    I have a pretty complex linq statement I need to access for different methods. Each of these methods may need to see the resulting data with different parameters. For one method it may be a project code, for another it may be language. The statement is pretty much the same it's just the where part which changes. I have not been able to figure out how to use different where statements without duplicating the entire linq statement, and that just isn't dry enough for me. For example (greatly simplified): var r = from c in customer where c.name == "some name" // or it may be var r = from c in customer where c.customerId == 8 Is there a way to have both of these in the same statement so I can use one or the other based on what I am doing? I tried an if statement to use one of the where statements or the other, and that didn't go over very well.

    Read the article

  • LINQ-to-SQL Query Timing Out

    - by kevinw
    I'm running this query in LINQ: var unalloc = db.slot_sp_getUnallocatedJobs("Repair", RadComboBox1.SelectedValue, 20); It runs when I first open the page, but when I go back to it and try to run the same query with a different value, "Con", being passed through, the linq to sql designer.cs tells me that I've got a timeout error. Any ideas? Edit: This is what's in the designer: [Function(Name="dbo.slot_sp_getUnallocatedJobs")] Public ISingleResult<slot_sp_getUnallocatedJobsResult> slot_sp_getUnallocatedJobs([Parameter(Name="JobType", DbType="VarChar(20)")] string jobType, [Parameter(Name="Contract", DbType="VarChar(10)")] string contract, [Parameter(Name="Num", DbType="Int")] System.Nullable<int> num) { IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), jobType, contract, num); return ((ISingleResult<slot_sp_getUnallocatedJobsResult>)(result.ReturnValue)); } } This is the error: SQLException was unhandled by user code Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

    Read the article

  • LINQ Quicksort is Unstable Except When Cascading

    - by Mystagogue
    On page 64 of "LINQ To Objects Using C# 4.0" (Tony Magennis) he states that LINQ's quicksort ordering algorithm is unstable... ...although this is simply solved by cascading the result into a ThenBy or ThenByDescending operator. Huh? Why would cascading an unstable sortation into another sortation fix the result? In fact, I'd say that isn't possible. The original order, once passed through an unstable sort, is simply lost. What am I missing here?

    Read the article

  • Return Count from Netflix oData Service When the LINQ Count() Method Doesn't Work

    - by Craig Shoemaker
    Is there a way to use a LINQ expression to request a Count query from the Netflix oData service? The Netflix documentation shows that you can return counts by appending $count to a request for a collection, but a URL like this: http://netflix.cloudapp.net/Catalog/Genres/$count Is not generated from an expression like this: var count = (from g in catalog.Genres select g).Count(); The above code returns an error saying that the Count method is not supported. Is there a way to do this in LINQ, or do I just need to make WebClient request to get the value?

    Read the article

< Previous Page | 25 26 27 28 29 30 31 32 33 34 35 36  | Next Page >