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
  • 0 Votes
    2 Posts
    2 Views
    N
    asp_victim wrote: I can understand how to insert data with Foreign keys and primary key Then what is your problem? I know the language. I've read a book. - _Madmatt
  • Linq Insert

    csharp tutorial linq
    8
    0 Votes
    8 Posts
    9 Views
    P
    Something like this: var customer=new Customer(12,"Pavel","Yermalovich"); YourDataContext db=new YourDataContext(); db.Customers.InsertOnSubmit(customer); db.SubmitChanges();
  • Linq - how to write code for this query

    csharp database linq help tutorial
    4
    0 Votes
    4 Posts
    2 Views
    S
    This should do the trick: var query = from row in dt.AsEnumerable() where row.Field<string>("MinValue") != null && row.Field<string>("MaxValue") != null group row by row.Field<string>("Name") into grp let maxServiceDate = grp.Max(r => r.Field<DateTime>("ServiceData")) from row in grp where row.Field<string;>("ServiceData") == maxServiceDate select row 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
  • How to convert a field in a LINQ query

    question csharp css database linq
    3
    0 Votes
    3 Posts
    4 Views
    B
    The string.format(IFormatprovider, string, object) overload method could help you format you date as you wish take a look on that link http://msdn.microsoft.com/en-us/library/1ksz8yb7.aspx[^]
  • How To Test If Linq Query Returned Results

    question csharp database linq tutorial
    6
    0 Votes
    6 Posts
    2 Views
    U
    Thanks Gideon - I hadn't used Any for that purpose. Awesome tip!
  • LINQ Scope Question

    tutorial database question csharp linq
    2
    0 Votes
    2 Posts
    2 Views
    H
    I think I may have found the info I need. I'm partway through reading this article but it's starting to make some sense now. The article is Simple LINQ to SQL in C#[^] just in case someone else faces the same issue. Denise "Hypermommy" Duggan
  • 0 Votes
    1 Posts
    1 Views
    No one has replied
  • LinqToSQL unit test in .NET error

    help testing question csharp beta-testing
    2
    0 Votes
    2 Posts
    3 Views
    S
    I got this one fix. In the LinqToSQL model (vsmdi file) I set the property for the contactId Identity = true. Thanks, Steve Holdorf
  • Insert opertion doesn't work

    sales help
    8
    0 Votes
    8 Posts
    3 Views
    S
    change xy.customers.insertonsubmit(cust); to xy.insertonsubmit(cust)
  • How to LINQ a List<T>

    csharp help linq data-structures regex
    7
    0 Votes
    7 Posts
    2 Views
    P
    yaa... got it but some other way return ( from cmd in cmds where cmd.KeyNum = KeyNum select cmd.execute() ).ToString();
  • 0 Votes
    1 Posts
    1 Views
    No one has replied
  • Count (Distinct) with left join and group by

    database csharp linq help tutorial
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied
  • storeprocedure

    3
    0 Votes
    3 Posts
    4 Views
    N
    When you do have a question try asking in the correct forum. All you have here is SQL, nothing about LINQ I know the language. I've read a book. - _Madmatt
  • 0 Votes
    3 Posts
    4 Views
    M
    I created a tree of expressions. How to get from the executable code. Need just a compiler, rather than Interpreter.
  • 0 Votes
    2 Posts
    4 Views
    A
    Hello! When i have similar situations i usually create a dummy SPROC that returns only empty data with the correct datatypes for each column. like: select CAST(0 as int) as CustomerNumber, CAST('x' as nvarchar(64)) as CustomerName, ....... and then comment all dynamic data in the SPROC. Then you can drag the SPROC into the dbml to get the correct return type. Once you hava a correct return type. restore your SPROC to the correct state. hope it helps Andreas Johansson IT Professional at Office IT Partner i Norrbotten Sweden What we don't know. We learn. What you don't know. We teach
  • Calrification on Linq

    database help csharp linq tutorial
    2
    0 Votes
    2 Posts
    2 Views
    J
    i found the answer .... i have changed these two lines in my linq query group new {patient, image} by new {patient.PatientStudyDataId, patient.DicomPatientName, patient.DicomPatientId, patient.DicomStudyDate, modality.Modality1 } into list and Count = list.Count(p =>p.image.ImageDataId ==p.image.ImageDataId) i am getting answer... anyway thanks for reading my question and answer... by joe
  • My linq update logic is not updating. help!

    csharp database linq help announcement
    3
    0 Votes
    3 Posts
    3 Views
    M
    :laugh: It looks like you ran into exactly my issue. I have a keytracker table doing the same thing and it wasn't updating and I wanted to pull out my hair. Just change your table def as so: KeyFile primarykey int default 666 KeyPrefix ... KeySuffix ... I then always get my record with the 666 key and my update logic works! :doh:
  • DBML generation and SQL UDF [modified]

    csharp database sql-server visual-studio linq
    2
    0 Votes
    2 Posts
    3 Views
    M
    The database generation is driven solely by the data in the database. If you have a function with parameters and no default value then you end up with nullable parameters every time. If you have fields in your table marked as nullable then your data is nullable. For parameters you can pretty much ignore the whole nullable thing if you always pass a parameter.
  • Exception while trying to change value of fk

    2
    0 Votes
    2 Posts
    4 Views
    M
    First off -- you will get a faster answer if you wrap your code with %lt;pre%gt; tags. So let's see if I isolated your code correctly: Account account = DBContext.ctx.Accounts.Single( a => a.Account_ID == idacco); account.Account_Name = txt_nameAccount.Text.ToString(); account.Account_code = Convert.ToInt32(txt_CodeAccount.Text); account.AssestID = newid ; DBContext.ctx.SubmitChanges(); So now that I can SEE your code, the problem with your code is that you are totally violating database rules. You are taking an existing record and trying to change the key with this statement: account.AssestID=newid; Just what the heck are you trying to do??? Anyone that has passed Coding 101 should know you cannot change a database key value. Another issue is that you have your context off somewhere precreated which will quickly become a source of a memory leak or worse. If you are trying to put in a new record your code should be as follows: using ( AccountsContext ctx = new AccountsContext()) { Account newRecord = new Account(); account.Account\_Name = blah blah bla ctx.Accounts.InsertOnSubmit(newRecord); ctx.SubmitChange(); } If you are trying to actually change the record ID from 'a' to 'b' then you must do more complex logic than what you have there. using ( AccountsContext ctx = new AccountsContext()) { Account oldRecord = ctx.Accounts.Single(a => a.Account\_ID == idacco); ctx.Accounts.DeleteOnSubmit(oldRecord); Account newRecord = new Account(); // make sure to use new instance ... set field values ctx.Accounts.InsertOnSubmit(newRecord); ctx.SubmitChanges(); }
  • Need to Convert This to LINQ

    database csharp linq sysadmin
    5
    0 Votes
    5 Posts
    2 Views
    D
    Hi thanks... I'm using VB... Found similar link to yours... As I said I'm new to LINQ so not sure if I'm approaching it the right way, but I thought would try and break it down into parts first... I tried serveral ways but here is one part I was trying to do. turning this SQL Statment Select '' as UniversalID, sEmailaddr as Email, uf.CLID, uf.CN,c.Company,p.First_name, P.Last_name, a.Address_Line_1 , a.Address_Line_2, a.City, a.State_Province, a.Country, a.Zip_Code, a.Phone_1 from UF_tbl uf inner join people p on p.CLID = uf.CLID and p.CN = uf.CN inner join address a on p.CLID = a.CLID and p.address_id = a.CN inner join Client c on c.CLID = p.CLID and c.CN = 0 where Email_Addr = sEmailAddr into this LINQ Dim AllPeople = From uf In BDDB.User_Fields _ Group Join p In BDDB.Peoples On p.CLID Equals uf.CLID And p.CN Equals uf.CN Into pInfo = Group _ Group Join a In BDDB.Addresses On a.CLID Equals 'got stuck trying to join a to p??? Or this LINQ Dim Contact = From p In BDDB.Peoples _ Group Join uf In BDDB.User_Fields On uf.CLID Equals p.CLID And uf.CN Equals p.CN Into ufInfo = Group _ Group Join a In BDDB.Addresses On a.CLID Equals p.CLID And a.CN Equals p.Address_Id Into addrInfo = Group _ Group Join c In BDDB.Clients On c.CLID Equals p.CLID And c.CN Equals 0 Into CoInfo = Group _ Where 'uf.email_addr = sEmailAddr??? Ok so they group into an alias but in the "Where" statement I can't get to the "uf" table anymore??? hmmm that's where they really lost me! Thanks for your Help... dotnetme2