Search Results

Search found 6252 results on 251 pages for 'linq expressions'.

Page 10/251 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • LINQ to SQL vs Entity Framework for an app with a future SQL Azure version

    - by Craig L
    I've got a vertical market Dot Net Framework 1.1 C#/WinForms/SQL Server 2000 application. Currently it uses ADO.Net and Microsoft's SQLHelper for CRUD operations. I've successfully converted it to Dot Net Framework 4 C#/WinForms/ SQL Server 2008. What I'd like to do is also offer my customers the ability to use SQL Azure as a backend storage for their data instead of local/LAN SQL Server. If I know SQL Azure is in my application's future, should I: A. Switch to LINQ to SQL B. Swith to Entity Framework C. Stick with ADO.Net and SQLHelper Thanks !

    Read the article

  • Linq query - multiple where, with extension method

    - by Cj Anderson
    My code works for ORs as I've listed it below but I want to use AND instead of OR and it fails. I'm not quite sure what I'm doing wrong. Basically I have a Linq query that searches on multiple fields in an XML file. The search fields might not all have information. Each element runs the extension method, and tests the equality. Any advice would be appreciated. refinedresult = From x In theresult _ Where x.<thelastname>.Value.TestPhoneElement(LastName) Or _ x.<thefirstname>.Value.TestPhoneElement(FirstName) Or _ x.<id>.Value.TestPhoneElement(Id) Or _ x.<number>.Value.TestPhoneElement(Telephone) Or _ x.<location>.Value.TestPhoneElement(Location) Or _ x.<building>.Value.TestPhoneElement(building) Or _ x.<department>.Value.TestPhoneElement(Department) _ Select x Public Function TestPhoneElement(ByVal parent As String, ByVal value2compare As String) As Boolean 'find out if a value is null, if not then compare the passed value to see if it starts with Dim ret As Boolean = False If String.IsNullOrEmpty(parent) Then Return False End If If String.IsNullOrEmpty(value2compare) Then Return ret Else ret = parent.ToLower.StartsWith(value2compare.ToLower.Trim) End If Return ret End Function

    Read the article

  • Compile error when calling ToList() when accessing many to many with Linq To Entities

    - by KallDrexx
    I can't figure out what I am doing wrong. I have the following method: public IList<WObject> GetRelationshipMembers(int relId) { var members = from r in _container.ObjectRelationships where r.Id == relId select r.WObjects; return members.ToList<WObject>(); } This returns the following error: Instance argument: cannot convert from 'System.Linq.IQueryable<System.Data.Objects.DataClasses.EntityCollection<Project.DomainModel.Entities.WObject>>' to 'System.Collections.Generic.IEnumerable<Project.DomainModel.Entities.WObject>' How can I convert the EntityCollection to a list without lazy loading?

    Read the article

  • How to do a STAR search in LINQ

    - by aNui
    I'm not sure about clarity of the STAR word. I'm implementing a search method using linq-to-object in c#. And I want to do a search with * (star) operator like most of search apps or web can do. e.g. If I typed "p*", results should be everything starting with "p". And it should work for prefix star, suffix star or star in the middle. And it would be great if the search can do with "-" (minus/NOT) operator or "+" (plus/OR) operator or "AND" operator Thanks in advance.

    Read the article

  • Dynamic Linq Library Help

    - by Alon
    Hi, I have the following class: public class Item { public Dictionary<string, string> Data { get; set; } } and a list of it: List<Item> items; I need to filter and order this list dynamicly using SQL-Like strings. The catch is, that I need to order it by the Data dictionary. For example: Order By Data["lastname"] or Where Data["Name"].StartsWith("a"). I thought to use the dynamic linq library, but is there any way that my clients can write without the Data[]? For example: Name.StartsWith("abc") instead of Data["Name"].StartsWith("abc") ? Thank you.

    Read the article

  • Using LINQ to find a common prefix?

    - by Roger Lipscombe
    I've got two sequences: IEnumerable<string> x = new[] { "a", "b", "c" }; IEnumerable<string> y = new[] { "a", "b", "d", "e" }; I'd like to find the common prefix of these two sequences (i.e. "a", "b"). Is there a succinct way to do this in LINQ? Bear in mind that these aren't really IEnumerable<string>; they're IEnumerable<PathComponent>, where I have an implementation of IEqualityComparer<PathComponent>.

    Read the article

  • how to convert Database Hierarchical Data to XML using ASP.net 3.5 and LINQ

    - by mahdiahmadirad
    hello guys! i have a table with hierarchical structure. like this: and table data shown here: this strategy gives me the ability to have unbounded categories and sub-categories. i use ASP.net 3.5 SP1 and LINQ and MSSQL Server2005. How to convert it to XML? I can Do it with Dataset Object and ".GetXML()" method. but how to implement it with LINQtoSQL or LINQtoXML??? or if there is another simpler way to perform that? what is your suggestion? the best way? I searched the web but found nothing for .net 3.5 featuers.

    Read the article

  • Converting SQL to LINQ to XML

    - by Morano88
    I'm writing the following code to convert SQL to LINQ and then to XML: SqlConnection thisConnection = new SqlConnection(@"Data Source=3BDALLAH-PC;Initial Catalog=XMLC;Integrated Security=True;Pooling=False;"); thisConnection.Open(); XElement eventsGive = new XElement("data", from c in ?????? select new XElement("event", new XAttribute("start", c.start), new XAttribute("end",c.eend), new XAttribute("title",c.title), new XAttribute("Color",c.Color), new XAttribute("link",c.link))); Console.WriteLine(eventsGive); The name of the table is "XMLC" and I want to refer to it. How can I do that? When I put its name directly VS gives an error. Also when I say thisConnection.XMLC it doesn't work.

    Read the article

  • linq to sql using foreign keys returning iqueryable(of myEntity]

    - by Gern Blandston
    I'm trying to use Linq to SQL to return an IQueryable(of Project) when using foreign key relationships. Using the below schema, I want to be able to pass in a UserId and get all the projects created for the company the user is associated with. DB tables: Projects Projid ProjCreator FK (UserId from UserInfo table) Companyid FK (CompanyID from Companies table) UserInfo UserID PK Companyid FK Companies CompanyId PK Description I can get the iqueryable(of project) when simply getting the ProjectCreator with this: Return (From p In db.Projects _ Where p.ProjectCreator = Me.UserId) But I'm having trouble getting the syntax to get a iqueryable(of projects) when using foreign keys. Below gives me an IQueryable(of anonymous) but I can't seem to convince it to give me an IQueryable(of project) even if I try to cast it: Dim retval = (From p In db.Projects _ Join c In db.Companies On p.CompanyId Equals c.CompanyId _ Join u In db.UserInfos On u.CompanyId Equals c.CompanyId _ Where u.Login = UserId)

    Read the article

  • Use delegate for Projection in Linq to SQL

    - by Redeemed1
    I have code something like this in an IRepository implementation in Linq to Sql: var newlist = from h in list where h.StringProp1 == "1" select new MyBusinessBO{ firstProp = h.StringProp1, secondProp = h.StringProp2 }; The projection into MyBusinessBO is not difificult but when the Business Object has many properties the projection code becomes very lengthy. Also, as the projection can occur in several places in the Repository we break the DRY principle. Is there any way to abstract out the projection or replace it with a delegate? I.e. replace the code firstProp = h.StringProp1, secondProp = h.StringProp2 with something reusable?

    Read the article

  • How to Expression.Invoke an arbitrary LINQ 2 SQL Query

    - by Remus Rusanu
    Say I take an arbitrary LINQ2SQL query's Expression, is it possible to invoke it somehow? MyContext ctx1 = new MyContext("..."); var q = from t in ctx1.table1 where t.id = 1 select t; Expression qe = q.Expression; var res = Expression.Invoke(qe); This throws ArgumentException "Expression of type System.Linq.IQueryable`1[...]' cannot be invoked". My ultimate goal is to evaluate the same query on several different data contexts.

    Read the article

  • VB.NET LINQ Result Set Manipulation.

    - by davemackey
    I have a table that looks like this: ID / Description / textValue / dateValue / timeValue / Type 1 / FRRSD / NULL / 2010-04-16 00:00:00.000 / NULL / classdates Now I've got a LINQ command to pull only the rows where the type is classdates from this table: Dim dbGetRegisterDates As New dcConfigDataContext Dim getDates = (From p In dbGetRegisterDates.webConfigOptions _ Where p.Type = "classdates" _ Select p) I now want to display the data in five different labels like so: lblClass1.Text = "Your class is from " & getDates.Description("FRRSD").dateValue & "to " & getDates.Description("FRRCD").dateValue Basically, I want to pull a row based on the description column value and then return the datevalue column value from that same row.

    Read the article

  • How to turn this linq query to lazy loading

    - by Luke101
    I would like to make a certain select item to lazy load latter in my linq query. Here is my query var posts = from p in context.post where p.post_isdeleted == false && p.post_parentid == null select new { p.post_date, p.post_id, p.post_titleslug, p.post_votecount, FavoriteCount = context.PostVotes.Where(x => x.PostVote_postid == p.post_id).Count() //this should load latter }; I have deleted the FavoriteCount item in the select query and would like it to ba added later based on certain conditions. Here is the way I have it lazy loaded if (GetFavoriteInfo) { posts = posts.Select(x => new { FavoriteCount = context.PostVotes.Where(y => y.PostVote_postid == x.post_id).Count() }); } I am getting a syntax error with this the above query. How do I fix this

    Read the article

  • Custom Grid LINQ to SQL help

    - by user488361
    Following is my custome cotrol grid... public partial class LinqGrid : UserControl { object tmpDataTable = new object(); public LinqGrid() { InitializeComponent(); } public void Bind(System.Data.Linq.Table listSource) where T : class { Project.dbClassesDataContext dbc = new Project.dbClassesDataContext(); tmpDataTable = listSource; var query = (from c in listSource select c); dgvRecords.DataSource = query.Take(10).ToList(); } private void btnNext_Click(object sender, EventArgs e) { // now what i have to do here if i want next 10 records.....means how to retrive tmpDataTable object here... ??? i can't find Type of variable....?? plz help me.... } }

    Read the article

  • Linq to Sql: Update Entity throug a new Object

    - by Dänu
    Hey Guys I'd like to update an entity via linq, but since I edit the entity in a view after serializing it, I don't have direct access to the entity inside the data context. I could do it like this: entity.property1 = obj.property1; entity.property2 = obj.property2; ... thats not cool... not cool at all. Next thing I tried is to do it via .attach() like so: context.Table.attach(entity, obj); doesn't work either. So is there another option short of reflection?

    Read the article

  • Linq to Entities custom ordering via position mapping table

    - by Bigfellahull
    Hi, I have a news table and I would like to implement custom ordering. I have done this before via a positional mapping table which has newsIds and a position. I then LEFT OUTER JOIN the position table ON news.newsId = position.itemId with a select case statement CASE WHEN [position] IS NULL THEN 9999 ELSE [position] END and order by position asc, articleDate desc. Now I am trying to do the same with Linq to Entities. I have set up my tables with a PK, FK relationship so that my News object has an Entity Collection of positions. Now comes the bit I can't work out. How to implement the LEFT OUTER JOIN. I have so far: var query = SelectMany (n => n.Positions, (n, s) => new { n, s }) .OrderBy(x => x.s.position) .ThenByDescending(x => x.n.articleDate) .Select(x => x.n); This kinda works. However this uses a INNER JOIN so not what I am after. I had another idea: ret = ret.OrderBy(n => n.ShufflePositions.Select(s => s.position)); However I get the error DbSortClause expressions must have a type that is order comparable. I also tried ret = ret.GroupJoin(tse.ShufflePositions, n => n.id, s => s.itemId, (n, s) => new { n, s }) .OrderBy(x => x.s.Select(z => z.position)) .ThenByDescending(x => x.n.articleDate) .Select(x => x.n); but I get the same error! If anyone can help me out, it would be much appreciated!

    Read the article

  • Handling auto-incrementing IDENTITY SQL Server fields with LINQ to SQL in C#

    - by Maxim Z.
    I'm building an ASP.NET MVC site that uses LINQ to SQL to connect to SQL Server, where I have a table that has an IDENTITY bigint primary key column that represents an ID. In one of my code methods, I need to create an object of that table to get its ID, which I will place into another object based on another table (FK-to-PK relationship). At what point is the IDENTITY column value generated and how can I obtain it from my code? Is the right approach to: Create the object that has the IDENTITY column Do an InsertOnSubmit() and SubmitChanges() to submit the object to the database table Get the value of the ID property of the object

    Read the article

  • LINQ-to-SQL class doesn't implement INotifyPropertyChanging & INotifyPropertyChanged if pulling from

    - by Traples
    I modified my data source in my LINQ-to-SQL class (by the old delete and drag back in method), and was surprised to see the INotifyPropertyChanging & INotifyPropertyChanged interfaces no longer implemented in the generated classes (MyDb.designer.cs). The methods for the individual fields went from looking like this... [Column(Storage="_Size", DbType="NVarChar(100)")] public string Size { get { return this._Size; } set { if ((this._Size != value)) { this.OnSizeChanging(value); this.SendPropertyChanging(); this._Size = value; this.SendPropertyChanged("Size"); this.OnSizeChanged(); } } } To looking like this... [Column(Storage="_Size", DbType="NVarChar(100)")] public string Size { get { return this._Size; } set { if ((this._Size != value)) { this._Size = value; } } } Any ideas on why this happens and how it will affect my application?

    Read the article

  • Combining 2 Linq queries into 1

    - by Mike Fielden
    Given the following information, how can I combine these 2 linq queries into 1. Having a bit of trouble with the join statement. 'projectDetails' is just a list of ProjectDetails ProjectDetails (1 to many) PCardAuthorizations ProjectDetails (1 to many) ExpenditureDetails Notice I am grouping by the same information and selecting the same type of information var pCardAccount = from c in PCardAuthorizations where projectDetails.Contains(c.ProjectDetail) && c.RequestStatusId == 2 group c by new { c.ProjectDetail, c.ProgramFund } into g select new { Key = g.Key, Sum = g.Sum(x => x.Amount) }; var expenditures = from d in ExpenditureDetails where projectDetails.Contains(d.ProjectDetails) && d.Expenditures.ExpenditureTypeEnum == 0 group d by new { d.ProjectDetails, d.ProgramFunds } into g select new { Key = g.Key, Sum = g.Sum(y => y.ExpenditureAmounts.FirstOrDefault(a => a.IsCurrent && !a.RequiresAudit).CommittedMonthlyRecords.ProjectedEac) };

    Read the article

  • LINQ-to-SQL: Searching against a CSV

    - by Peter Bridger
    I'm using LINQtoSQL and I want to return a list of matching records for a CSV contains a list of IDs to match. The following code is my starting point, having turned a CSV string in a string array, then into a generic list (which I thought LINQ would like) - but it doesn't: Error Error 22 Operator '==' cannot be applied to operands of type 'int' and 'System.Collections.Generic.List<int>' C:\Documents and Settings\....\Search.cs 41 42 C:\...\ Code DataContext db = new DataContext(); List<int> geographyList = new List<int>( Convert.ToInt32(geography.Split(',')) ); var geographyMatches = from cg in db.ContactGeographies where cg.GeographyId == geographyList select new { cg.ContactId }; Where do I go from here?

    Read the article

  • LINQ 2 SQL Insert Error(with Guids)

    - by Refracted Paladin
    I have the below LINQ method that I use to create the empty EmploymentPLan. After that I simply UPDATE. For some reason this works perfectly for myself but for my users they are getting the following error -- The target table 'dbo.tblEmploymentPrevocServices' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause. This application is a WinForm app that connects to a local SQL 2005 Express database that is a part of a Merge Replication topology. This is an INTERNAL App only installed through ClickOnce. public static Guid InsertEmptyEmploymentPlan(int planID, string user) { using (var context = MatrixDataContext.Create()) { var empPlan = new tblEmploymentQuestionnaire { PlanID = planID, InsertDate = DateTime.Now, InsertUser = user, tblEmploymentJobDevelopmetService = new tblEmploymentJobDevelopmetService(), tblEmploymentPrevocService = new tblEmploymentPrevocService() }; context.tblEmploymentQuestionnaires.InsertOnSubmit(empPlan); context.SubmitChanges(); return empPlan.EmploymentQuestionnaireID; } }

    Read the article

  • LINQ 2 SQL Insert Error

    - by Refracted Paladin
    I have the below LINQ method that I use to create the empty EmploymentPLan. After that I simply UPDATE. For some reason this works perfectly for myself but for my users they are getting the following error -- The target table 'dbo.tblEmploymentPrevocServices' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause. This application is a WinForm app that connects to a local SQL 2005 Express database. public static Guid InsertEmptyEmploymentPlan(int planID, string user) { using (var context = MatrixDataContext.Create()) { var empPlan = new tblEmploymentQuestionnaire { PlanID = planID, InsertDate = DateTime.Now, InsertUser = user, tblEmploymentJobDevelopmetService = new tblEmploymentJobDevelopmetService(), tblEmploymentPrevocService = new tblEmploymentPrevocService() }; context.tblEmploymentQuestionnaires.InsertOnSubmit(empPlan); context.SubmitChanges(); return empPlan.EmploymentQuestionnaireID; } }

    Read the article

  • Mixing LINQ to SQL with properties of objects in a generic list

    - by BPotocki
    I am trying to accomplish something like this query: var query = from a in DatabaseTable where listOfObjects.Any(x => x.Id == a.Id) select a; Basically, I want to filter the results where a.Id equals a property of one of the objects in the generic list "listOfObjects". I'm getting the error "Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator." Any ideas on how to filter this in an easily readable way using "contains" or another method? Thanks in advance.

    Read the article

  • How to assign one object to another in Linq c# without making new

    - by LLL
    I m facing issue in assiging one object to another in linq sql. In this example Func<result, result> make = q => new result { Id = q.Id, lName = q.lName, GroupId = q.GroupId, Age = (from tags in q.age where tags.Del == null && tags.lId == q.Id select age).ToEntitySet(), }; p = (from q in dc.results where q.Id == Id.Value select make(q)).First(); i am making new and assigning the object, but i dont want to do this, it will cause propblem in insertion. so i want to assign without making new, how is it possible?

    Read the article

  • LINQ Lycanthropy: Transformations into LINQ

    LINQ is one of the few technologies that you can start to use without a lot of preliminary learning. Also, it lends itself to learning by trying out examples. With Michael Sorens' help, you can watch as your conventional C# code changes to ravenous LINQ before your very eyes. Join SQL Backup’s 35,000+ customers to compress and strengthen your backups "SQL Backup will be a REAL boost to any DBA lucky enough to use it." Jonathan Allen. Download a free trial now.

    Read the article

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