score:4
Accepted answer
public tblopportunity getopportunitybycode(string clientcode, string opportunitycode)
{
tblopportunity opportunity = null;
var convertedopportunitycode = convert.toint32(opportunitycode);
connectionhandler.invoke<entityconnection>((connection) =>
{
var context = new dmsentities();
opportunity = context.tblopportunities.firstordefault<tblopportunity>(o => o.clientcode == clientcode && o.opportunitycode == convertedopportunitycode);
});
return opportunity;
}
score:1
public tblopportunity getopportunitybycode(
string clientcode, string opportunitycode)
{
tblopportunity opportunity = null;
var convertedopportunitycode = convert.toint32(opportunitycode);
connectionhandler.invoke<entityconnection>((connection) =>
{
var context = new xxentities();
opportunity = context.tblopportunities
.firstordefault(o =>
o.clientcode == clientcode &&
o.opportunitycode == convertedopportunitycode);
});
return opportunity;
}
score:1
public tblopportunity getopportunitybycode(string clientcode, string opportunitycode) {
tblopportunity opportunity = null;
// do the conversion outside linq
var opcodeint = convert.toint32(opportunitycode);
connectionhandler.invoke<entityconnection>((connection) => {
var context = new xxentities();
opportunity = context.tblopportunities.firstordefault<tblopportunity>(
o => o.clientcode == clientcode && o.opportunitycode == opcodeint
); // ^^^^^^^^^
});
return opportunity;
}
Source: stackoverflow.com
Related Query
- Specific linq exception when converting string to int. LINQ to Entities does not recognize the method 'Int32 ToInt32(System.Object)' m
- LINQ to Entities does not recognize the method 'Int32 ToInt32 Converting String to Int
- LINQ to Entities does not recognize the method 'System.String ToString()' method when converting Nullable DateTime
- LINQ to Entities does not recognize the method exception
- LINQ to Entities does not recognize the method 'Boolean HasFlag(System.Enum)' when creating the expression via System.Linq.Expressions.Expression
- LINQ query does not compile when using double, float, or decimal instead of int
- linq to entities can not convert int to string
- LINQ to Entities does not recognize convert to string
- Linq OrderBy issue when converting string to int with space
- Error: LINQ to Entities does not recognize the method 'System.String ToString(System.Object)' method occurs while string conversion
- Error with converting int to string in Linq to entities
- "LINQ to Entities does not recognize the method" when Convert to Int 32
- LINQ anonym object with result to delimited string (LINQ to Entities does not recognize the method 'System.String ToString()' method)
- Converting linq select into model, LINQ to Entities does not recognize the method, and this method cannot be translated into a store expression
- LINQ to Entities does not recognize the method 'System.String ToString()'. Error happend when trying parse DateTime
- LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression
- LINQ to Entities does not recognize the method
- LINQ to Entities does not recognize the method 'System.String Format(System.String, System.Object, System.Object)'
- LINQ to Entities does not recognize the method Int32 get_Item(Int32)
- LINQ to Entities does not recognize the method 'System.TimeSpan Subtract(System.DateTime)' method
- LINQ to Entities does not recognize the method 'System.DateTime GetValueOrDefault()'
- Why LINQ to Entities does not recognize the method 'System.String ToString()?
- LINQ to Entities does not recognize the method 'System.Linq.IQueryable`
- LINQ to Entities does not recognize the method 'System.DateTime AddSeconds(Double)' method, and this method cannot be translated into
- LINQ to Entities does not recognize the method 'System.Object GetValue(...)'
- LINQ to Entities does not recognize the method 'Int32 Int32(System.String)' method, and this method cannot be translated into a store expression
- LINQ to Entities does not recognize the method ElementAt(i);
- LINQ to Entities does not recognize the method 'System.String StringConvert(System.Nullable`1[System.Double])
- Linq to Entities does not recognize string.Format or concatenation '+'
- Why does LINQ query throw an exception when I attempt to get a count of a type
More Query from same tag
- LINQ: How to join on only a single row with the MAX ID of the join column, and not all rows?
- Repeated subtraction of rows from a column using LINQ and C#
- How can I create an Lambda Expression for Linq in the Where clause for two tables after the Join?
- Why can't I use Linq Select in subclass of List<string> using base.Select?
- Find Element when XPath is variable
- I am using linq and I am getting the error "There is already an open datareader associated with this command which must be closed first"
- Count related entities without loading them, non-generic way
- LINQ to Razor View SubQuery with Alias Value
- List.OrderByDescending Linq not working
- Integration testing web services against a testing database
- EF7 - How to get values from DbSet before change
- Dynamic lambda for IEnumerable.Select
- How to use LINQ to populate a object with a List<int> and a String?
- LINQ Aggregate results with Many to Many Relationship
- Python equivalent of LINQ All function?
- How to convert System.Data.Linq.Binary to a Stream?
- Using LinqKit to Apply a Query to a Single Complex Property
- How can Entity Framework queries be reused (using methods)?
- MVC Repository Pattern query caching issue
- LINQ - List within a List filtering
- FindAll Vs Where
- Conditional LINQ query on self-joining table with 2 sets of data
- Turn an IObservable<IEnumerable<T>> into an IEnumerable<IObservable<T>>
- How can I fix this LINQ function?
- Multiple randomly selection Linq
- Dynamically selecting fields in a linq query
- Linq logic in the select statement
- LINQ generate entity without my consent
- C# Expression to sort generic query by key field
- how to optimize a linq query c# complex object?