Search Results

Search found 19804 results on 793 pages for 'linq to xml'.

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

  • compiling a linq to sql query

    - by frenchie
    Hi, I have queries that are built like this: public static List<MyObjectModel> GetData (int MyParam) { using (DataModel MyModelDC = new DataModel()) { var MyQuery = from.... select MyObjectModel { ...} } return new List<MyObjectModel> (MyQuery) } } It seems that using compiled linq-to-sql queries are about as fast as stored procedures and so the goal is to convert these queries into compiled queries. What's the syntax for this? Thanks.

    Read the article

  • Linq with EF dynamic search

    - by malik
    I am using EF 3.5 with MVC. I want to made a search page, has some fields for criteria like date, int etc. What is the way in linq to entities to filter the result dynamically. If there are one parameter we can use .where(a=a.id==1) but many combination with optional param how can i load results and then pass to model.

    Read the article

  • LINQ TO SQL, Dynamic query with DATE type fields

    - by acanthus
    Hello, I'm building a query with the LINQ dynamic library so I don't know how many potential parameters will I have and I get an error when trying to query DATE type fields: Operator '=' incompatible with operand types 'DateTime' and 'String' When I step through the debugger in the Dynamic.cs it shows that the value is of type string and the field is of type date so the problem is obvious but I have no idea how to approach it. Any ideas? BR

    Read the article

  • Translate LINQ to sql statement

    - by zielu1
    Hi, I want to translate LINQ expression tree to SQL statement and I don't want to write my own code for this. Example: var query = from c in Customers where c.Country == "UK" && c.City == "London" select c); To SELECT ... FROM Customers AS c WHERE c.Country = "UK" AND c.City = "London" I know DataContext.Log, but I want to use: query.ToSqlStatementString() Thanks

    Read the article

  • Getting multiple data items in an element with linq to xml

    - by Maestro1024
    Getting multiple data items in an element with linq to xml I have an xml file like this <TopLevel> <Inside> Jibba </Inside> <Inside> Jabba </Inside> </TopLevel> I was given said xml and and want to get all the elements. Here is the code I have. var q = from c in loaded.Descendants("TopLevel") select (XElement)c.Element("Inside"); I tried c.Elements but that did not work. What do I need to do to get all of the internal elements? This code just gets the first "Inside" tag.

    Read the article

  • Getting a set of elements using linq

    - by MarceloRamires
    I have the following piece of XML: <xml> <ObsCont xCampo="field1"> <xTexto>example1</xTexto> </ObsCont> <ObsCont xCampo="field2"> <xTexto>example2</xTexto> </ObsCont> <ObsCont xCampo="field3"> <xTexto>example3</xTexto> </ObsCont> </xml> How do I (using linq) get for example what is inside the xTexto tag that has as parent the ObsCont with the xCampo attribute "field2" ? (c#, vb.net, your choice)

    Read the article

  • Linq to xml not able to add new elements

    - by Fore
    We save our xml in a "text" field in the database. So first I check if it exist any xml, if not I create a new xdocument, fill it with the necessary xml. else i just add the new element. Code looks like this: XDocument doc = null; if (item.xmlString == null || item.xmlString == "") { doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new XElement("DataTalk", new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"), new XAttribute(XNamespace.Xmlns + "xsd", "http://www.w3.org/2001/XMLSchema"), new XElement("Posts", new XElement("TalkPost")))); } else { doc = XDocument.Parse(item.xmlString); } This is working alright to create a structure, but then the problem appears, when I want to add new TalkPost. I get an error saying incorrectly structured document. The following code when adding new elements: doc.Add(new XElement("TalkPost", new XElement("PostType", newDialog.PostType), new XElement("User", newDialog.User), new XElement("Customer", newDialog.Customer), new XElement("PostedDate", newDialog.PostDate), new XElement("Message", newDialog.Message)));

    Read the article

  • Order by descending based on condition

    - by Vinni
    Hello All, I want to write a LINQ to Entity query which does order by ascending or descending based on input parameter, Is there any way for that. Following is the my code. Please suggest. public List<Hosters_HostingProviderDetail> GetPendingApproval(SortOrder sortOrder) { List<Hosters_HostingProviderDetail> returnList = new List<Hosters_HostingProviderDetail>(); int pendingStateId = Convert.ToInt32(State.Pending); //If the sort order is ascending if (sortOrder == SortOrder.ASC) { var hosters = from e in context.Hosters_HostingProviderDetail where e.ActiveStatusID == pendingStateId orderby e.HostingProviderName ascending select e; returnList = hosters.ToList<Hosters_HostingProviderDetail>(); return returnList; } else { var hosters = from e in context.Hosters_HostingProviderDetail where e.StateID == pendingStateId orderby e.HostingProviderName descending select e; returnList = hosters.ToList<Hosters_HostingProviderDetail>(); return returnList; } }

    Read the article

  • Linq-to-Sql not detecting change in xml

    - by porum
    I have an xml field (Answers) in Sql Server, but when changing the content via Linq-to-Sql, the record is not flagged for updating. e.g. in Linqpad... var profile = Profiles.FirstOrDefault(p => p.Answers != null); profile.Answers.SetAttributeValue("date", DateTime.Now.ToString()); GetChangeSet().Dump(); // nothing flagged profile.Answers = new XElement(profile.Answers); // ends up with correct xml GetChangeSet().Dump(); // record is flagged as changed Any suggestions apart from assigning a clone of itself to the field or storing the xml as a string to force the update?

    Read the article

  • Repository vs Data Access

    - by vdh_ant
    Hi guys In the context of the n-tier application, is there a difference between what you would consider your data access classes to be and your repositories? I tend to think yes but I just wanted to see what other thought. My thinking is that the job of the repository is just to contain and execute the raw query itself, where as the data access class would create the context, execute the repository (passing in the context), handle mapping the data model to the domain model and return the result back up... What do you guys think? Also do you see any of this changing in a Linq to XML scenario (assuming that you change the context for the relevant XDocument)? Cheers Anthony

    Read the article

  • Problem with XML Deserialization C#

    - by alex
    I am having trouble with XML deserialization. In a nutshell - I have 2 classes: SMSMessage SMSSendingResponse I call an API that takes a bunch of parameters (represented by SMSMessage class) It returns an XML response. The response looks like this: <?xml version="1.0" encoding="utf-8"?> <data> <status>1</status> <message>OK</message> <results> <result> <account>12345</account> <to>012345678</to> <from>054321</from> <message>Testing</message> <flash></flash> <replace></replace> <report></report> <concat></concat> <id>f8d3eea1cbf6771a4bb02af3fb15253e</id> </result> </results> </data> Here is the SMSMessage class (with the xml serialization attributes so far) using System.Xml.Serialization; namespace XMLSerializationHelp { [XmlRoot("results")] public class SMSMessage { public string To { get { return Result.To; } } public string From { get { return Result.From; } } public string Message { get { return Result.Message; } } [XmlElement("result")] public Result Result { get; set; } } } Here is SMSMessageSendingResponse: using System.Xml.Serialization; namespace XMLSerializationHelp { [XmlRoot("data")] public class SMSSendingResponse { //should come from the results/result/account element. in our example "12345" public string AccountNumber { get { return SMSMessage.Result.AccountNumber; } } //should come from the "status" xml element [XmlElement("status")] public string Status { get; set; } //should come from the "message" xml element (in our example - "OK") [XmlElement("message")] public string Message { get; set; } //should come from the "id" xml element (in our example - "f8d3eea1cbf6771a4bb02af3fb15253e") public string ResponseID { get { return SMSMessage.Result.ResponseID; } } //should be created from the results/result element - ignore flash, replace, report and concat elements for now. [XmlElement("results")] public SMSMessage SMSMessage { get; set; } } } Here is the other class (Result) - I want to get rid of this, so only the 2 previously mentioned classes remain using System.Xml.Serialization; namespace XMLSerializationHelp { [XmlRoot("result")] public class Result { [XmlElement("account")] public string AccountNumber{ get; set; } [XmlElement("to")] public string To { get; set; } [XmlElement("from")] public string From { get; set; } [XmlElement("message")] public string Message { get; set; } [XmlElement("id")] public string ResponseID { get; set; } } } I don't want SMSMessage to be aware of the SMSSendingResponse - as this will be handled by a different part of my application

    Read the article

  • Instantiate object from Linq to XML Query

    - by objectsbinding
    Hi All I have the following class public class CountrySpecificPIIEntity { public string Country { get; set; } public string CreditCardType { get; set; } public String Api { get; set; } public List<String> FilterList { get; set; } } I am trying to use a linq to XMl query to create a list of instances of type CountrySpecificPIIEntity. The XML is as below <piisettings> <country countrycode="DE"> <creditcardype credicardtype="mastercard"> <api api="INSERT_FILTERS"> <filters> <filter>FIRSTNAME</filter> <filter>HOUSENUMBER</filter> <filter>ADDITIONALADDRESSINFO</filter> <filter>EMAIL</filter> </filters> </api> </creditcardype> <creditcardype credicardtype="visa"> <api api="INSERT_FILTERS"> <filters> <filter>STATE</filter> <filter>EMAIL</filter> </filters> </api> </creditcardype> <creditcardype credicardtype="visa"> <api api="UPDATE_FILTERS"> <filters> <filter>STATE</filter> <filter>EMAIL</filter> </filters> </api> </creditcardype> </country> <country countrycode="GB"> <creditcardype credicardtype="americanexpress"> <api api="INSERT_FILTERS"> <filters> <filter>STREET</filter> <filter>ZIP</filter> <filter>CITY</filter> <filter>STATE</filter> <filter>EMAIL</filter> </filters> </api> </creditcardype> <creditcardype credicardtype="debank"> <api api="INSERT_FILTERS"> <filters> <filter>IPADDRESSCUSTOMER</filter> <filter>FIRSTNAME</filter> <filter>SURNAME</filter> <filter>HOUSENUMBER</filter> <filter>STREET</filter> <filter>ZIP</filter> <filter>CITY</filter> <filter>STATE</filter> <filter>EMAIL</filter> </filters> </api> </creditcardype> </country> </piisettings> what should the Linq to XML query be?

    Read the article

  • XDocument + IEnumerable is causing out of memory exception in System.Xml.Linq.dll

    - by Manatherin
    Basically I have a program which, when it starts loads a list of files (as FileInfo) and for each file in the list it loads a XML document (as XDocument). The program then reads data out of it into a container class (storing as IEnumerables), at which point the XDocument goes out of scope. The program then exports the data from the container class to a database. After the export the container class goes out of scope, however, the garbage collector isn't clearing up the container class which, because its storing as IEnumerable, seems to lead to the XDocument staying in memory (Not sure if this is the reason but the task manager is showing the memory from the XDocument isn't being freed). As the program is looping through multiple files eventually the program is throwing a out of memory exception. To mitigate this ive ended up using System.GC.Collect(); to force the garbage collector to run after the container goes out of scope. this is working but my questions are: Is this the right thing to do? (Forcing the garbage collector to run seems a bit odd) Is there a better way to make sure the XDocument memory is being disposed? Could there be a different reason, other than the IEnumerable, that the document memory isnt being freed? Thanks. Edit: Code Samples: Container Class: public IEnumerable<CustomClassOne> CustomClassOne { get; set; } public IEnumerable<CustomClassTwo> CustomClassTwo { get; set; } public IEnumerable<CustomClassThree> CustomClassThree { get; set; } ... public IEnumerable<CustomClassNine> CustomClassNine { get; set; }</code></pre> Custom Class: public long VariableOne { get; set; } public int VariableTwo { get; set; } public DateTime VariableThree { get; set; } ... Anyway that's the basic structures really. The Custom Classes are populated through the container class from the XML document. The filled structures themselves use very little memory. A container class is filled from one XML document, goes out of scope, the next document is then loaded e.g. public static void ExportAll(IEnumerable<FileInfo> files) { foreach (FileInfo file in files) { ExportFile(file); //Temporary to clear memory System.GC.Collect(); } } private static void ExportFile(FileInfo file) { ContainerClass containerClass = Reader.ReadXMLDocument(file); ExportContainerClass(containerClass); //Export simply dumps the data from the container class into a database //Container Class (and any passed container classes) goes out of scope at end of export } public static ContainerClass ReadXMLDocument(FileInfo fileToRead) { XDocument document = GetXDocument(fileToRead); var containerClass = new ContainerClass(); //ForEach customClass in containerClass //Read all data for customClass from XDocument return containerClass; } Forgot to mention this bit (not sure if its relevent), the files can be compressed as .gz so I have the GetXDocument() method to load it private static XDocument GetXDocument(FileInfo fileToRead) { XDocument document; using (FileStream fileStream = new FileStream(fileToRead.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { if (String.Compare(fileToRead.Extension, ".gz", true) == 0) { using (GZipStream zipStream = new GZipStream(fileStream, CompressionMode.Decompress)) { document = XDocument.Load(zipStream); } } else { document = XDocument.Load(fileStream); } return document; } } Hope this is enough information. Thanks Edit: The System.GC.Collect() is not working 100% of the time, sometimes the program seems to retain the XDocument, anyone have any idea why this might be?

    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

  • LinQ XML mapping to a generic type

    - by Manuel Navarro
    I´m trying to use an external XML file to map the output from a stored procedure into an instance of a class. The problem is that my class is of a generic type: public class MyValue<T> { public T Value { get; set; } } Searching through a lot of blogs an articles I've managed to get this: <?xml version="1.0" encoding="utf-8" ?> <Database Name="" xmlns="http://schemas.microsoft.com/linqtosql/mapping/2007"> <Table Name="MyValue" Member="MyNamespace.MyValue`1" > <Type Name="MyNamespace.MyValue`1"> <Column Name="Category" Member="Value" DbType="VarChar(100)" /> </Type> </Table> <Function Method="GetResourceCategories" Name="myprefix_GetResourceCategories" > <ElementType Name="MyNamespace.MyValue`1"/> </Function> </Database> The MyNamespace.MyValue`1 trick works fine, and the class is recognized. I expect four rows from the stored procedure, and I'm getting four MyValue<string> instances, but the big problem is that the property Value for the all four instances is null. The property is not getting mapped and I don't really get why. Maybe worth noting that the property Value is generic, and that when the mapping is done using attributes it works perfect. Anyone have a clue? BTW the method GetResourceCategories: public ISingleResult<MyValue<string>> GetResourceCategories() { IExecuteResult result = this.ExecuteMethodCall( this, (MethodInfo)MethodInfo.GetCurrentMethod()); return (ISingleResult<MyValue<string>>)result.ReturnValue; }

    Read the article

  • Why is the use of abstractions (such as LINQ) so taboo?

    - by Matthew Patrick Cashatt
    I am an independent contractor and, as such, I interview 3-4 times a year for new gigs. I am in the midst of that cycle now and got turned down for an opportunity even though I felt like the interview went well. The same thing has happened to me a couple of times this year. Now, I am not a perfect guy and I don't expect to be a good fit for every organization. That said, my batting average is lower than usual so I politely asked my last interviewer for some constructive feedback, and he delivered! The main thing, according to the interviewer, was that I seemed to lean too much towards the use of abstractions (such as LINQ) rather than towards lower-level, organically grown algorithms. On the surface, this makes sense--in fact, it made the other rejections make sense too because I blabbed about LINQ in those interviews as well and it didn't seem that the interviewers knew much about LINQ (even though they were .NET guys). So now I am left with this question: If we are supposed to be "standing on the shoulders of giants" and using abstractions that are available to us (like LINQ), then why do some folks consider it so taboo? Doesn't it make sense to pull code "off the shelf" if it accomplishes the same goals without extra cost? It would seem to me that LINQ, even if it is an abstraction, is simply an abstraction of all the same algorithms one would write to accomplish exactly the same end. Only a performance test could tell you if your custom approach was better, but if something like LINQ met the requirements, why bother writing your own classes in the first place? I don't mean to focus on LINQ here. I am sure that the JAVA world has something comparable, I just would like to know why some folks get so uncomfortable with the idea of using an abstraction that they themselves did not write. UPDATE As Euphoric pointed out, there isn't anything comparable to LINQ in the Java world. So, if you are developing on the .NET stack, why not always try and make use of it? Is it possible that people just don't fully understand what it does?

    Read the article

  • Are there any good resources for refactoring existing C# code to use LINQ while keeping your tests passing?

    - by Paddyslacker
    I've been teaching myself a little LINQ and an exercise I thought would be useful was to take my existing Project Euler C# code, which I built using Test Driven Development and gradually convert it to LINQ. I realise that LINQ is not always the best solution for all of the Project Euler problems, but I don't want to get into that here. I'm wondering whether or not it's feasible to refactor "traditional" OO C# code to use LINQ and functional programming syntax whilst keeping all of your tests passing. I can't find a way to make the tiny steps I'm used to making using TDD when converting to LINQ and this is a roadblock for me. I seem to have to make large changes to come up with a single function that I then replace whole chunks of my code with. I realise I could write this from scratch in LINQ, but in the real world, I'd like to be able to replace parts of my existing C# code to take advantage of LINQ where appropriate. Has anyone been successful with this approach? What resources did you find useful for refactoring existing C# code to use LINQ whilst taking a Test Driven Development approach?

    Read the article

  • Linq2sql code generator misbehaving

    - by Martin
    Sometime the linq2sql just makes its mind up about things. I've been pulling my hair for the past hours trying to work out what I'm doing differently from all the other times when I don't get ForeignKeyReferenceAlreadyHasValueException. Turns out that if (this._Activity.HasLoadedOrAssignedValue) { throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException(); } is present on my primary key in this particular table, and in no other. No matter what I do with the association, I've even tried deleting and dragging the thing back to the designer, it's still there and I'm sure it's not supposed to be. I know why, of course, but I don't know why, so to speak. A while back the association went the other way. Whereas I've left that era behind me, the code generator seems to exhibit phantom pains. The same phenomenon, is responsible for me having to change the namespace in the designer.cs everytime I make changes in the designer. I made the mistake of renaming my namespace and the code generator just doesn't get it. Somebody please help this poor boy out.

    Read the article

  • How to store a list in a column of a database table.

    - by John Berryman
    Howdy! So, per Mehrdad's answer to a related question, I get it that a "proper" database table column doesn't store a list. Rather, you should create another table that effectively holds the elements of said list and then link to it directly or through a junction table. However, the type of list I want to create will be composed of unique items (unlike the linked question's fruit example). Furthermore, the items in my list are explicitly sorted - which means that if I stored the elements in another table, I'd have to sort them every time I accessed them. Finally, the list is basically atomic in that any time I wish to access the list, I will want to access the entire list rather than just a piece of it - so it seems silly to have to issue a database query to gather together pieces of the list. AKX's solution (linked above) is to serialize the list and store it in a binary column. But this also seems inconvenient because it means that I have to worry about serialization and deserialization. Is there any better solution? If there is no better solution, then why? It seems that this problem should come up from time to time. ... just a little more info to let you know where I'm coming from. As soon as I had just begun understanding SQL and databases in general, I was turned on to LINQ to SQL, and so now I'm a little spoiled because I expect to deal with my programming object model without having to think about how the objects are queried or stored in the database. Thanks All! John

    Read the article

  • Is saving to database just to get an ID a bad hack?

    - by Narsil
    I hope the title is not too confusing. I am trying to make folders with linq-to-sql objects' IDs. Actually I have to create folders before I should save them. I will use them to keep user uploaded files. As you can see I have to create the folder with the FileID before I can save it there. So I just save a record which will be edited or maybe deleted File newFile = new File(); ...//add some values to fields so they don't throw rule violations db.AddFile(newFile); db.Save(); System.IO.Directory.CreateDirectory("..Uploads/"+newFile.FileId.ToString()); After that I will have to edit some fields and save again. Of course user might stop upload and I would have to delete it. I know I can write a stored procedure to get the next available FileID but some other upload happening at the same time would get the same number. So they would write in same directory which is a thing I don't want. Should I go on with this, would there be some problems? Can you think of a better way?

    Read the article

  • Passing in a lambda to a Where statement

    - by sonicblis
    I noticed today that if I do this: var items = context.items.Where(i => i.Property < 2); items = items.Where(i => i.Property > 4); Once I access the items var, it executes only the first line as the data call and then does the second call in memory. However, if I do this: var items = context.items.Where(i => i.Property < 2).Where(i => i.Property > 4); I get only one expression executed against the context that includes both where statements. I have a host of variables that I want to use to build the expression for the linq lambda, but their presence or absence changes the expression such that I'd have to have a rediculous number of conditionals to satisfy all cases. I thought I could just add the Where() statements as in my first example above, but that doesn't end up in a single expression that contains all of the criteria. Therefore, I'm trying to create just the lambda itself as such: //bogus syntax if (var1 == "something") var expression = Expression<Func<item, bool>>(i => i.Property == "Something); if (var2 == "somethingElse") expression = expression.Where(i => i.Property2 == "SomethingElse"); And then pass that in to the where of my context.Items to evaluate. A) is this right, and B) if so, how do you do it?

    Read the article

  • How to serialize a Linq to Sql object graph without hiding the child's "Parent" member

    - by Richard B
    Without hiding the Child object's reference to the Parent object, has anyone been able to use an XmlSerializer() object to move a Linq to SQL object to an XML document, or is the only appropriate way of handling this to create a custom serialization/deserialization class to handle moving the data to/from the xml document? I don't like the idea of hiding the child object's reference to the parent object is why I'm asking. Thx.

    Read the article

  • Nullable One To One Relationships with Integer Keys in LINQ-to-SQL

    - by Craig Walker
    I have two objects (Foo and Bar) that have a one-to-zero-or-one relationship between them. So, Foo has a nullable foreign key reference to Bar.ID and a (nullbusted) unique index to enforce the "1" side. Bar.ID is an int, and so Foo.BarID is a nullable int. The problem occurs in the LINQ-to-SQL DBML mapping of .NET types to SQL datatypes. Since int is not a nullable type in .NET, it gets wrapped in a Nullable<int>. However, this is not the same type as int, and so Visual Studio gives me this error message when I try to create the OneToOne Association between them: Cannot create an association "Bar_Foo". Properties do not have matching types: "ID", "BarID". Is there a way around this?

    Read the article

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