Skip to content

LINQ

LINQ (all flavours)

This category can be followed from the open social web via the handle linq-e04cf296@forum.codeproject.com

783 Topics 2.8k Posts
  • How to setting ConnectionString of LinqtoSql's dbml

    question tutorial
    3
    0 Votes
    3 Posts
    2 Views
    M
    Establish a connection string in your app.config Then your calls to the database will be as follows: using ( MyContext context = new MyContext( ConfigurationManager.ConnectionStrings["mydb"].connectionstring)) { }
  • insert record other than AddToEntityName

    com sales
    2
    0 Votes
    2 Posts
    2 Views
    M
    You will only get something like that if you write a WCF service and have the parameters passed. Even then, your parameters would be strongly typed. Overall, though, I don't understand what you have against creating a new entity and calling an add. It guarantees your data is strongly typed and valid which cuts down on database chattiness. You will never find a database method where you are passing name value pairs to create a record.
  • Need help with complicated? XML query

    csharp database linq xml help
    2
    0 Votes
    2 Posts
    2 Views
    M
    The xml you present is very flat xml. What I'd expect to see is something like this for running a linq query against: <Transitions> <ActionTransition action="Advance"> .... </ActionTransition> <ActionTransition action="Initial"> ... <ActionTransition action="Something"> </Transitions> Your ActionTransition object would then be accessible via it's depths ActionTransition.Transition.FinalStatus.{finalStatusProperty} I'm not 100% certain but I believe you need a recurring entity in your xml to make linq to xml useful.
  • Rename stored procedure within DBML file?

    database csharp asp-net sql-server sysadmin
    2
    0 Votes
    2 Posts
    2 Views
    M
    Select the stored procedure in the windowed interface and pull up Properties. The property for the stored procedures contains to elements: Name Source The source ties your SPROC to the one in the database. The Name is the one you see in code. Just change the name property from ProcGetOrders to Orders and you are good to go.
  • How to use LINQ to DATASET

    csharp linq tutorial
    3
    0 Votes
    3 Posts
    2 Views
    P
    jaja :laugh: :laugh: that's the best page I've ever seen! found everything... //ds = DataSet with 1 table... //cust = var to asign the Data... //c.Field("customerid") = customerid is a string value of the table 0 of the DS... and companyname too var custs = from c in ds.Tables[0].ToQueryable() select new { cid = c.Field("customerid"), co = c.Field("companyname") }; so... what have you expected? Is the same LINQ to SQL... ;)
  • Get Column Dynamically in LINQ

    csharp database linq tutorial
    2
    0 Votes
    2 Posts
    2 Views
    D
    Well here's a possible solution using reflection: //a dummy class public class Price { public decimal Eur { get; set; } public decimal USD { get; set; } } //a dummy list List<Price> prices = new List<Price>(); private void button1\_Click(object sender, EventArgs e) { prices.Add(new Price { Eur = 3.2m, USD = 4.1m }); //option1 => use a separate method var result = (from rec in prices select GetValue(rec, "Eur")).First(); //option2 => inline it var result2 = (from rec in prices select rec.GetType().GetProperty("USD").GetValue(rec, null)).First(); MessageBox.Show(result.ToString()); MessageBox.Show(Convert.ToDecimal(result2).ToString()); } private decimal GetValue(Price pr, string propName) { return (decimal)pr.GetType().GetProperty(propName).GetValue(pr, null); } } Of course the "EUR" or "USD" will be a method param or something, not hard coded as in this example. Hope It helps.
  • How to write Linq for this T-SQL

    csharp database linq tutorial
    2
    0 Votes
    2 Posts
    3 Views
    S
    You need to use the Contains operator; var list = new List { 1,2,3,.... }; var query = dc.Table.Where( t=>list.Contains(t.ID) ); Syed Mehroz Alam My Blog | My Articles Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein
  • I need help with LINQ dynamic building

    csharp linq sysadmin help tutorial
    3
    0 Votes
    3 Posts
    4 Views
    P
    That would work if I use 'DataAccessDataContext' (a defined datacontext) I understand. But in my case I want to make it more generic. Using the base class inherited (DataContext) of all .dbml files! It doesn't work like I've tried. :(( Maybe there is some way but was out of ideas so I've used a SqlDataAdapter to fill the query and that's all!! but thanks for your help!! :)
  • 0 Votes
    3 Posts
    4 Views
    R
    Modify your code as below, it will work public static IEnumerable GetbyKeywordLookup(string keywords) { var results = from o in BookProxy.Readall() where o.TagName.ToString().Contains(keywords.Trim()) Rashmi.M.K
  • How to add data into a table of relational

    tutorial question
    2
    0 Votes
    2 Posts
    3 Views
    N
    If userID and purviewID are primary keys for the tables then no the underlying framework will take care of it I know the language. I've read a book. - _Madmatt
  • 0 Votes
    14 Posts
    4 Views
    D
    OK. Maybe I understood you wrong. Here's what I think you need to acomplish => correct me if I'm wrong. So, you need to get like all the data about books based on the book keywords/tags and the keywords introduced by user. If that's what you need then this is a working solution: (feel free to create a new windows app, add 2 buttons and paste the code to check): /// <summary> /// check if contains any keywords /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnContainsAny_Click(object sender, EventArgs e) { string tags = "science fiction futurist 1024 cores 25 GHz"; string user = "fiction core"; if (MyContainsAny(tags, user)) { string message = String.Format("At least one keyword form \"{0}\" was found in \r\n" + "\"{1}\"", user, tags); MessageBox.Show(message); } } /// <summary> /// check if contains all keywords /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnContainsAll\_Click(object sender, EventArgs e) { string tags = "science fiction futurist 1024 cores 25 GHz"; string user = "fiction core"; if (MyContainsAll(tags, user)) { string message = String.Format("All the keywords form \\"{0}\\" were found in \\r\\n" + "\\"{1}\\"", user, tags); MessageBox.Show(message);//as you can see it finds core in cores } } /// <summary> /// used to see if the tag contains ANY of the keywords introduced by user /// </summary> /// <param name="tag"></param> /// <param name="userData"></param> /// <returns></returns> private bool MyContainsAny(string tag, string userData) { string\[\] words = userData.Trim().Split(" "); foreach (var item in words) { if (tag.Contains(item)) { return true; } } return false; } /// <summary> /// used to see if the tag contains ALL of the keywords introduced by user /// </
  • 0 Votes
    2 Posts
    3 Views
    D
    In LINQ to SQL, the data model of a relational database is mapped to an object model expressed in the programming language of the developer. It doesn't work with data table but with objects that are maping a table or... Here's a fine introduction to LINQ to SQL.
  • about LinqDatasource

    asp-net csharp database com help
    2
    0 Votes
    2 Posts
    3 Views
    N
    Why don't you give the author a change to respond to your question before posting it here. I know the language. I've read a book. - _Madmatt modified on Friday, March 5, 2010 11:19 AM
  • Using mdb databases in Linq?

    csharp database linq question
    5
    0 Votes
    5 Posts
    4 Views
    O
    Thanks so much.
  • SQL to Linq translation

    csharp help database linq tutorial
    3
    0 Votes
    3 Posts
    3 Views
    G
    Thanks for the reply I can't use the stored procedure since the application can use an online Db, or may be used (with limited functionality) as an 'offline' application via SQL CE... so I have to find some way of duplicating the functionality.
  • Declare query in or out of loop?

    database csharp linq tutorial question
    2
    0 Votes
    2 Posts
    2 Views
    P
    i think first option is better one and its working because of linq differed execution take place for more detail :- http://www.codeproject.com/tips/59614/Linq-Deferred-Execution.aspx[^]
  • 0 Votes
    2 Posts
    2 Views
    D
    Hi there, I have found the solution to this, along the lines of what I thought might be happening. You need to populate the context with the new items by calling Load(). So, in the example above it would be like this: using(NorthWindEntities ctx = new NorthWindEntities()){ var query = ctx.Territories.First(c => c.TerritoryID == "01581"); Label1.Text = query.TerritoryDescription; query.Employees1.Load(); <<<<<<<<<<<<<<<<<<<<<<<<<<<< hydrate the Employees using Load(); Label2.Text = query.Employees1.Count.ToString(); } Still not quite sure about the appended "1". Hope this helps someone.
  • Multiple Unique Requirements

    question csharp database linq business
    10
    0 Votes
    10 Posts
    5 Views
    L
    It is returning what I expected.. So I was just wondering why you said it was not the same. It makes sence what you have said though.. specifically the modifcation you made. Thank you! ASCII stupid question, get a stupid ANSI
  • LINQ to HTML/XML C#

    csharp html linq com xml
    2
    0 Votes
    2 Posts
    2 Views
    D
    I'm just stating the obvious but there is [EDIT] no [/EDit] XLINQ method to get "nodes" inside a XCDATA.Just the value/text wich is everything inside the XCData. You have to manually set up a routine to extract the needed data(s). Wich can be quite easy if all you ever need to get is the <img src="...". modified on Tuesday, February 16, 2010 10:29 PM
  • Row number in gridview using linq [Solved]

    csharp css linq help
    8
    0 Votes
    8 Posts
    2 Views
    K
    thank you! is there any way to put numbers directly in grid or table column? foreach has a long delay!