This is a migrated thread and some comments may be shown as answers.

Searching and filtering with WCF Endpoint services

6 Answers 135 Views
Web Services
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
inanc
Top achievements
Rank 1
inanc asked on 24 Jun 2011, 11:36 AM
Hello,
I am trying to use OpenAccess ORM with Data Services Wizard. I chosed WCF End Points Service. I've created an client web application with name 'UI'.

I've got an example table called  as 'IhaleSekilleri'
IhaleSekilleri has only two columns like 
Id and IhaleSekilAdi.

Table includes sample data given below.

Id IhaleSekilAdi
1 KIK-19
2 KIK-21F
3 KIK-21B
4 KIK-21C
5 KIK-21D

When I look into SampleServiceName.svc.cs , I see a method like ,


public List<IhaleTakipDataServisi.IhaleSekilleri> SearchIhaleSekilleri(IhaleTakipDataServisi.IhaleSekilleri searchParameters)
        {
            return this.dataManager.SearchEntities<IhaleTakipDataServisi.IhaleSekilleri>(searchParameters);
        }


My wish is to use that WCF method to searc on IhaleSekilAdi column. There is no problem with the Id column when searching.

   
using (SampleServiceNameClient client = new SampleServiceNameClient())
     {
            ServiceReference1.IhaleSekilleri sepa0 = new ServiceReference1.IhaleSekilleri();
             sepa0.Id = 3;
             var result0 = client.SearchIhaleSekilleri(sepa0);
    }


result0 includes one entity as expected


But result1 returns empty. I can not figure out why?
and for the result1,
   
using (SampleServiceNameClient client = new SampleServiceNameClient())
      {
             ServiceReference1.IhaleSekilleri sepa1 = new ServiceReference1.IhaleSekilleri();
              sepa1.IhaleSekilAdi = "KIK-19";
              var result1 = client.SearchIhaleSekilleri(sepa1);
    }



How can I use search method for that table forexample? Any best practices examples for specialy searching and filtering for the version  2011.1.411.2 (latest version for today)?
Kind Regards









6 Answers, 1 is accepted

Sort by
0
A.Alexandrov
Telerik team
answered on 27 Jun 2011, 05:36 PM
Hi inanc,

Please tell us what is the value of property ID after this line is executed:

ServiceReference1.IhaleSekilleri sepa1 = new ServiceReference1.IhaleSekilleri();
We consider that it should be 0, but maybe this is not the case. If it is not equal to 0, please set the default value to be 0 and try again.

Greetings,
A.Alexandrov
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
0
Brandon
Top achievements
Rank 2
answered on 07 Sep 2011, 02:12 PM
I too am having a problem associated with WCF EndPoints. I'm getting the following error:

Expression expected

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]: Expression expected

Source Error:

Line 13595:        
Line 13596:        public Altruistic.Services.Web.Provider[] SearchProvider(Altruistic.Services.Web.Provider searchParameters) {
Line 13597:            return base.Channel.SearchProvider(searchParameters);
Line 13598:        }
Line 13599:        

Source File: c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\f547f707\9b26e63d\App_WebReferences.jagco-hi.0.cs    Line: 13597


When trying to execute the following code:
var providerName = engageResponse.GetElementsByTagName("profile")[0]["providerName"].InnerText;
var username = engageResponse.GetElementsByTagName("profile")[0]["preferredUsername"].InnerText;
var identifier = engageResponse.GetElementsByTagName("profile")[0]["identifier"].InnerText;
 
 
using (var dataService = new DataServiceClient())
{
    var searchParameters = new Provider() {Desc = providerName};
 
    searchParameters.Desc = providerName;
 
    var providers = dataService.SearchProvider(searchParameters);
}
 
Response.Write("Fin");
Response.End();
0
A.Alexandrov
Telerik team
answered on 07 Sep 2011, 05:14 PM
Hello Brandon,

Unfortunately we are not able to tell where is the problem from the given information. Please if it is possible, provide us with a sample application, which we can examine. That will really help us a lot. If it is not possible you can send us only the rlinq file that contains the used Domain Model.

Regards,
A.Alexandrov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

0
Brandon
Top achievements
Rank 2
answered on 08 Sep 2011, 12:17 PM
Hello there,

Thank you for getting back with me so quickly. As it turns out, I wasn't using the latest & greatest ORM & since updating my references, that problem was solved, but now I'm having the exact same problem as the previous person in this thread.

The code I posted before returns a count of 0, but if I search on ProviderId, then the search returns the correct record.

*** UPDATE ***

I just ran SQL Profiler with the code from above and it showed the following:

SELECT a.[ProviderId] AS COL1, a.[Description] AS COL2
FROM [Providers] a
WHERE a.[ProviderId] = 0 AND a.[Description] = 'Google' ORDER BY a.[ProviderId]


Why is it passing in a ProviderId? I'd think that the WHERE clause should simply be a.[Description] = 'Google'.

How do I stop it from passing 0 in for the ProviderId?
0
A.Alexandrov
Telerik team
answered on 09 Sep 2011, 07:44 AM
Hello Brandon,

this is a bug in our implementation for the Search<T> method in the DataManager class. So please first replace the code of the following method in the DataManager class:

001.public List<T> SearchEntities<T>(T searchParameters)
002. 
003.{
004. 
005.    var parameters = new List<KeyValuePair<string, object>>();
006. 
007.   
008. 
009.    string typeName = typeof(T).Name;
010. 
011.    Telerik.OpenAccess.Metadata.MetaPersistentType type =
012. 
013.        this._openAccessContext.Metadata.PersistentTypes.FirstOrDefault(
014. 
015.        t => t.Name.Equals(typeName));
016. 
017.   
018. 
019.    if (type == null || searchParameters == null)
020. 
021.    {
022. 
023.        return new List<T>();
024. 
025.    }
026. 
027.   
028. 
029.    foreach (var item in typeof(T).GetProperties(
030. 
031.        BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public))
032. 
033.    {
034. 
035.        try
036. 
037.        {
038. 
039.            Telerik.OpenAccess.Metadata.MetaMember member =
040. 
041.                type.Members.FirstOrDefault(p => p.PropertyName.Equals(item.Name));
042. 
043.   
044. 
045.   
046. 
047.            bool isMetaPrimitiveMember = member is Telerik.OpenAccess.Metadata.MetaPrimitiveMember;
048. 
049.   
050. 
051.            if (isMetaPrimitiveMember)
052. 
053.            {
054. 
055.                var value = item.GetValue(
056. 
057.                    searchParameters,
058. 
059.                    BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public,
060. 
061.                    null,
062. 
063.                    null,
064. 
065.                    CultureInfo.InvariantCulture);
066. 
067.   
068. 
069.                // Makes sure the property is not the default value.  
070. 
071.                // ! Cannot execute Equals(value, default((Type)variable)) - this does not compile! Using null converts this to 0 for value-types, so it works.  
072. 
073.                if (!Equals(value, null))
074. 
075.   
076. 
077.   
078. 
079.                {
080. 
081.                    parameters.Add(new KeyValuePair<string, object>(
082. 
083.                        item.Name,
084. 
085.                        value));
086. 
087.                }
088. 
089.            }
090. 
091.        }
092. 
093.        catch
094. 
095.        {
096. 
097.            // Not sure what would happen here.  
098. 
099.            continue;
100. 
101.        }
102. 
103.    }
104. 
105.   
106. 
107.    var paramString = new StringBuilder();
108. 
109.    var paramValues = new ArrayList();
110. 
111.    for (var i = 0; i < parameters.Count; i++)
112. 
113.    {
114. 
115.        if (i > 0)
116. 
117.        {
118. 
119.            paramString.Append(" and ");
120. 
121.        }
122. 
123.   
124. 
125.        paramString.Append(parameters[i].Key);
126. 
127.        paramString.Append(" = @");
128. 
129.        paramString.Append(i.ToString());
130. 
131.   
132. 
133.        paramValues.Add(parameters[i].Value);
134. 
135.    }
136. 
137.   
138. 
139.    try
140. 
141.    {
142. 
143.        var results = this._openAccessContext.GetAll<T>().Where(
144. 
145.            paramString.ToString(),
146. 
147.            paramValues.ToArray());
148. 
149.   
150. 
151.        return results.ToList();
152. 
153.    }
154. 
155.    catch (OpenAccessException ex)
156. 
157.    {
158. 
159.        this._openAccessContext.ClearChanges();
160. 
161.        throw ex;
162. 
163.    }
164. 
165.}
with this one:
001.public List<T> SearchEntities<T>(T searchParameters)
002. 
003.{
004. 
005.    var parameters = new List<KeyValuePair<string, object>>();
006. 
007.   
008. 
009.    string typeName = typeof(T).Name;
010. 
011.    Telerik.OpenAccess.Metadata.MetaPersistentType type =
012. 
013.        this._openAccessContext.Metadata.PersistentTypes.FirstOrDefault(
014. 
015.        t => t.Name.Equals(typeName));
016. 
017.   
018. 
019.    if (type == null || searchParameters == null)
020. 
021.    {
022. 
023.        return new List<T>();
024. 
025.    }
026. 
027.   
028. 
029.    foreach (var item in typeof(T).GetProperties(
030. 
031.        BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public))
032. 
033.    {
034. 
035.        try
036. 
037.        {
038. 
039.            Telerik.OpenAccess.Metadata.MetaMember member =
040. 
041.                type.Members.FirstOrDefault(p => 
042. 
043.                    p.PropertyName != null &&
044. 
045.                    p.PropertyName.Equals(item.Name));
046. 
047.            bool isMetaPrimitiveMember = member is Telerik.OpenAccess.Metadata.MetaPrimitiveMember;
048. 
049.   
050. 
051.            if (isMetaPrimitiveMember)
052. 
053.            {
054. 
055.                var value = item.GetValue(
056. 
057.                    searchParameters,
058. 
059.                    BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public,
060. 
061.                    null,
062. 
063.                    null,
064. 
065.                    CultureInfo.InvariantCulture);
066. 
067.   
068. 
069.                object defaultValue =
070. 
071.                    item.PropertyType.IsValueType ?
072. 
073.                    Activator.CreateInstance(item.PropertyType) :
074. 
075.                    null;
076. 
077.                if (!Equals(value, defaultValue))
078. 
079.                {
080. 
081.                    parameters.Add(new KeyValuePair<string, object>(
082. 
083.                        item.Name,
084. 
085.                        value));
086. 
087.                }
088. 
089.            }
090. 
091.        }
092. 
093.        catch
094. 
095.        {
096. 
097.            // Not sure what would happen here.  
098. 
099.            continue;
100. 
101.        }
102. 
103.    }
104. 
105.   
106. 
107.    var paramString = new StringBuilder();
108. 
109.    var paramValues = new ArrayList();
110. 
111.    for (var i = 0; i < parameters.Count; i++)
112. 
113.    {
114. 
115.        if (i > 0)
116. 
117.        {
118. 
119.            paramString.Append(" and ");
120. 
121.        }
122. 
123.   
124. 
125.        paramString.Append(parameters[i].Key);
126. 
127.        paramString.Append(" = @");
128. 
129.        paramString.Append(i.ToString());
130. 
131.   
132. 
133.        paramValues.Add(parameters[i].Value);
134. 
135.    }
136. 
137.   
138. 
139.    try
140. 
141.    {
142. 
143.        var results = this._openAccessContext.GetAll<T>().Where(
144. 
145.            paramString.ToString(),
146. 
147.            paramValues.ToArray());
148. 
149.   
150. 
151.        return results.ToList();
152. 
153.    }
154. 
155.    catch (OpenAccessException ex)
156. 
157.    {
158. 
159.        this._openAccessContext.ClearChanges();
160. 
161.        throw ex;
162. 
163.    }
164. 
165.}
Second, you should ensure that all tables have a primary key defined and all entities have a property which is an identity.

The fix about this problem will be provided in the upcoming service pack of Telerik OpenAccess ORM. We are very sorry for the troubles caused. If you need further assistance we will be more than happy to assist you. 


Kind regards,
A.Alexandrov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

0
Brandon
Top achievements
Rank 2
answered on 09 Sep 2011, 09:39 AM
That did the trick. Thanks!
Tags
Web Services
Asked by
inanc
Top achievements
Rank 1
Answers by
A.Alexandrov
Telerik team
Brandon
Top achievements
Rank 2
Share this question
or