[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1340
  • Last Modified:

Binding LINQ to datalist?

I'm not sure why this is failing.

I have the datakeyfield and the datasourceid correct, but I get an error on load with the following:

DataBinding: '<>f__AnonymousType0`2[[DataObjects.Property, DataObjects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=495a38a4eda10835],[System.Collections.Generic.IEnumerable`1[[DataObjects.GarageType, DataObjects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=495a38a4eda10835]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' does not contain a property with the name 'propertyId'.
protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
        {

            DataClassesDataContext db = new DataClassesDataContext();
            var propertyReturn = from p in db.Properties
                                 join g in db.GarageTypes on p.GarageType equals g.garageTypeId into gp
                                 where p.listingType == 1
                                 from g in gp.DefaultIfEmpty()
                                 select new { p, gp };

            e.Result = propertyReturn;

        }

Open in new window

0
ApexCo
Asked:
ApexCo
  • 2
  • 2
  • 2
  • +1
1 Solution
 
gemailjCommented:
then try to close only the old reader without closing the connection

there are to readers reading from the same  opened connection
try
{
	SqlConnection con = new SqlConnection(strCon);
	SqlCommand cmd = new SqlCommand("Select * from xTable");
	con.Open();
	try
	{
		SqlDataReader reader1 = cmd.ExecuteReader();
	}
	finally
	{
		reader1.Close();
	}
	try
	{
		cmd = new SqlCommand("Select * from yTable");
		SqlDataReader reader2 = cmd.ExecuteReader();
	}
	finally
	{
		reader2.Close();
	}
}
finally
{
	con.Close();
}

Open in new window

0
 
gemailjCommented:
sorry this comment was for another question
0
 
tovvenkiCommented:
Hi,
Where do you have propertyId? are you binding it to any column.

Thanks and regards,
Venki
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
ApexCoAuthor Commented:
Well, I'm mapping it to a datalist and there isn't really a column so to speak.


<asp:DataList ID="dataList" runat="Server" DataSourceID="LinqDataSource1"  DataKeyField="propertyId">
                    <ItemTemplate>
                        <div id="propertyWrap">
                            <div id="propertyImage">
                                <a href='propertydetail.aspx?propertyid=<%# Eval("propertyId") %>'>
                                    <img src="" alt="" /></a>
                            </div>
                            <div id="propertyBrief">
                                <div id="title">
                                    <a href='propertydetail.aspx?propertyid=<%# Eval("propertyId") %>'>
                                        <%# Eval("listingtitle") %></a>
                                </div>
                                <div id="price">
                                    Price:
                                    <%# Eval("price") %></div>
                                <div id="description">
                                    Description:
                                    <%# Eval("Description") %></div>
                                <div id="features">
                                    <div id="bedroom">
                                        Bedrooms:
                                        <%# Eval("bedrooms") %></div>
                                    <div id="bathroom">
                                        Bathrooms:
                                        <%# Eval("bathrooms") %></div>
                                    <div id="garagetype">
                                        GarageType<%# Eval("garagetype") %></div>
                                </div>
                            </div>
                        </div>
                    </ItemTemplate>
                    <AlternatingItemTemplate>
                    </AlternatingItemTemplate>
                </asp:DataList>

Open in new window

0
 
tovvenkiCommented:
hey,
Might be a silly questions I am sorry for that, I could see that you are setting datakeyfield and a hyperlink query string to propertyId. Are you sure that this column is there in the table and is coming along when you load the query.

Thanks and regards,
Venki
0
 
ApexCoAuthor Commented:
Hi,

I have definitely gone through debugging and inspected the object. Everything is there, including propertyId.
0
 
kumar754Commented:
you anonymous type contains multiple entity list or you can say collection within each Item

since you are returning this:

 select new { p, gp };


did you tried using this ???

<%# Eval("p.listingtitle") %>
<%# Eval("p.price") %></div>
<%# Eval("gp.Description") %></div>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now