The type arguments for method cannot be inferred from the usage. Try specifying the type arguments explicitly.
-
Tuesday, April 10, 2012 1:20 AM
Hi
I have an service that has to LinqToEntitiesDomainService tables in them called towns and buildings. I added an IEnumerable with variables. I now get the following error when I built:
The type arguments for method 'System.ServiceModel.DomainServices.Client.DomainContext.Load<TEntity>(System.ServiceModel.DomainServices.Client.EntityQuery<TEntity>, System.Action<System.ServiceModel.DomainServices.Client.LoadOperation<TEntity>>, object)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
My code in the service:
public IEnumerable<string> GetStatisticsBuildingsTownTenure(string tableName, string columnName, string ObjectDiscription, string Region, string tenure) { string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; using (var conn = new SqlConnection(connStr)) using (var cmd = conn.CreateCommand()) { conn.Open(); string sqlSelect = ""; if (tableName == "TProperty_Data") { sqlSelect = "SELECT DISTINCT ISNULL(dbo.TProperty_Data.Town, 0) AS Town " + "FROM dbo.TRegions " + "INNER JOIN dbo.THead_Property ON dbo.TRegions.Region_Ref = dbo.THead_Property.Region_Ref " + "INNER JOIN dbo.TProperty_Data ON dbo.THead_Property.Head_Property_ID = dbo.TProperty_Data.Head_Property_ID " + "WHERE (dbo.TProperty_Data.Town IS NOT NULL) AND dbo.THead_Property.Region_Ref = '" + Region + "' AND Tenure = '" + tenure + "' " + "GROUP BY town"; } else { sqlSelect = "SELECT DISTINCT ISNULL(dbo.TProperty_Data.Town, 0) AS Town " + "FROM dbo.TRegions " + "INNER JOIN dbo.THead_Property ON dbo.TRegions.Region_Ref = dbo.THead_Property.Region_Ref " + "INNER JOIN dbo.TProperty_Data ON dbo.THead_Property.Head_Property_ID = dbo.TProperty_Data.Head_Property_ID " + "INNER JOIN dbo." + tableName + " ON TProperty_Data.Property_ID = " + tableName + ".PropertyID" + "WHERE (dbo.TProperty_Data.Town IS NOT NULL) AND dbo.THead_Property.Region_Ref = '" + Region + "' AND " + columnName + " in '" + ObjectDiscription + "' " + "GROUP BY town"; } List<string> strList = new List<string>(); SqlDataAdapter da = new SqlDataAdapter(sqlSelect, conn); DataTable dt = new DataTable(); da.Fill(dt); foreach (DataRow dr in dt.Rows) { strList.Add(dr.ItemArray[0].ToString()); } return strList.ToList(); } }My code in my view:
LoadOperation<rStatisticsTown> mp = this.stb.Load(this.stb.GetStatisticsBuildingsTownTenure(TableName, ColumnName, ojb, Region, tenure), LoadBehavior.RefreshCurrent, true);
This is where my error lies. Please can anyone give any insight.
Thank you
All Replies
-
Tuesday, April 10, 2012 3:19 AM
you can change code "return strList.ToList();" to "return strList;"
try, good luck
-
Tuesday, April 10, 2012 4:05 AM
Hi
Still gives me the same error.
-
Thursday, April 12, 2012 1:39 AM
HI,please refer to the code below:
Use [Invoke] attribute to the method.
[Invoke] public IEnumerable<string> GetStatisticsBuildingsTownTenure(string tableName, string columnName, string ObjectDiscription, string Region, string tenure) { List<string> strList = new List<string>(); for (int i = 0; i < 20; i++) { strList.Add(i.ToString()); } return strList.ToList(); }public MainPage() { InitializeComponent(); DomainService1 stb = new DomainService1(); stb.GetStatisticsBuildingsTownTenure("", "", "", "", "").Completed+=new EventHandler(GetStatisticsBuildingsTownTenure_Completed); } void GetStatisticsBuildingsTownTenure_Completed(object sender, EventArgs e) { var list = ((System.ServiceModel.DomainServices.Client.InvokeOperation<System.Collections.Generic.IEnumerable<string>>)(sender)).Value as IList<string>; }

