Click here to Skip to main content
15,889,595 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# program on windows server 2003 Pin
LeonXjm4-May-14 17:38
LeonXjm4-May-14 17:38 
QuestionGIS coordinates (spherical mercator) to screen coordinates? Pin
SledgeHammer0121-Apr-14 12:42
SledgeHammer0121-Apr-14 12:42 
AnswerRe: GIS coordinates (spherical mercator) to screen coordinates? Pin
Bernhard Hiller21-Apr-14 21:38
Bernhard Hiller21-Apr-14 21:38 
Questioncustom webcontrol designer problems Pin
Nico Haegens21-Apr-14 7:41
professionalNico Haegens21-Apr-14 7:41 
QuestionBy using the web services/WCF of Amazon (and other retailers) my client can upload there products on Amazon (and other sites) in bulk. Pin
Santosh K. Tripathi20-Apr-14 23:08
professionalSantosh K. Tripathi20-Apr-14 23:08 
SuggestionRe: By using the web services/WCF of Amazon (and other retailers) my client can upload there products on Amazon (and other sites) in bulk. Pin
Santosh K. Tripathi27-Apr-14 21:00
professionalSantosh K. Tripathi27-Apr-14 21:00 
QuestionC# Linq To SQL Dynamic Where Clause Pin
Kevin Marois20-Apr-14 11:39
professionalKevin Marois20-Apr-14 11:39 
AnswerRe: C# Linq To SQL Dynamic Where Clause Pin
Richard Deeming22-Apr-14 2:07
mveRichard Deeming22-Apr-14 2:07 
You need to call the Where extension method[^] using the method syntax instead of the query syntax.

However, since you're using a Func<T, bool> to filter the records, the filter cannot be translated to a SQL query. As a result, all records will be loaded into memory before being passed to the filter to see if they match. If you change your code to use an Expression<Func<T, bool>>, the filter will be passed to SQL, and only the matching records will be returned.

You can also avoid the Activator.CreateInstance call by adding the new() constraint to your generic type parameter.

C#
private T deleteClientAddresses<T>(Expression<Func<ClientAddressEntity, bool>> whereClause) where T : _ResponseBase, new()
{
    var response = new T();
 
    using (var dc = getDataContext())
    {
        var entities = dc.ClientAddresses.Where(whereClause);
 
        foreach (var entity in entities)
        {
            ...
        }
    }
 
    return response;
}

public DeleteByAddressIdResponse DeleteByAddressId(int Id)
{
    Expression<Func<ClientAddressEntity, bool>> whereClause = ca => ca.AddressId == Id;
    return deleteClientAddresses<DeleteByAddressIdResponse>(whereClause);
}
 
public DeleteByAddressTypeIdResponse DeleteByAddressTypeId(int Id)
{
    Expression<Func<ClientAddressEntity, bool>> whereClause = ca => ca.AddressTypeId == Id;
    return deleteClientAddresses<DeleteByAddressTypeIdResponse>(whereClause);
}

public DeleteByClientIdResponse DeleteByClientId(int Id)
{
    Expression<Func<ClientAddressEntity, bool>> whereClause = ca => ca.ClientId == Id;
    return deleteClientAddresses<DeleteByClientIdResponse>(whereClause);
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: C# Linq To SQL Dynamic Where Clause Pin
Kevin Marois22-Apr-14 5:41
professionalKevin Marois22-Apr-14 5:41 
GeneralRe: C# Linq To SQL Dynamic Where Clause Pin
Richard Deeming22-Apr-14 6:32
mveRichard Deeming22-Apr-14 6:32 
GeneralRe: C# Linq To SQL Dynamic Where Clause Pin
Kevin Marois22-Apr-14 6:37
professionalKevin Marois22-Apr-14 6:37 
GeneralRe: C# Linq To SQL Dynamic Where Clause Pin
Richard Deeming22-Apr-14 6:42
mveRichard Deeming22-Apr-14 6:42 
GeneralRe: C# Linq To SQL Dynamic Where Clause Pin
Kevin Marois22-Apr-14 6:44
professionalKevin Marois22-Apr-14 6:44 
Questionknapsack Pin
Member 1076234920-Apr-14 9:52
Member 1076234920-Apr-14 9:52 
AnswerRe: knapsack Pin
Pete O'Hanlon20-Apr-14 11:46
mvePete O'Hanlon20-Apr-14 11:46 
AnswerRe: knapsack Pin
OriginalGriff20-Apr-14 20:49
mveOriginalGriff20-Apr-14 20:49 
GeneralRe: knapsack Pin
Pete O'Hanlon20-Apr-14 21:57
mvePete O'Hanlon20-Apr-14 21:57 
GeneralRe: knapsack Pin
OriginalGriff20-Apr-14 22:04
mveOriginalGriff20-Apr-14 22:04 
QuestionRe: knapsack Pin
ZurdoDev21-Apr-14 9:37
professionalZurdoDev21-Apr-14 9:37 
Questionknap sack Pin
Member 1076234920-Apr-14 9:43
Member 1076234920-Apr-14 9:43 
AnswerRe: knap sack Pin
Pete O'Hanlon20-Apr-14 9:50
mvePete O'Hanlon20-Apr-14 9:50 
GeneralRe: knap sack Pin
Manfred Rudolf Bihy20-Apr-14 10:22
professionalManfred Rudolf Bihy20-Apr-14 10:22 
GeneralRe: knap sack Pin
Wes Aday20-Apr-14 10:31
professionalWes Aday20-Apr-14 10:31 
AnswerRe: knap sack Pin
OriginalGriff20-Apr-14 20:48
mveOriginalGriff20-Apr-14 20:48 
GeneralRe: knap sack Pin
harold aptroot21-Apr-14 7:17
harold aptroot21-Apr-14 7:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.