1

I wrote a defining query

 <EntitySet Name="EntityFramework" EntityType="SEOAnalysisModel.Store.EntityFramework">
     <DefiningQuery>
         SELECT Keyword, ResultHead ,Year from SeoAnalysis where Year = 2005
     </DefiningQuery>
 </EntitySet>

And entity type for custom entity

 <EntityType Name="EntityFramework">
     <Key>
         <PropertyRef Name="Year" />
     </Key>
     <Property Name="Year" Nullable="false" Type="int" />
     <Property Name="Keyword" Nullable="false" MaxLength="1000" Type="varchar" />
     <Property Name="ResultHead" Nullable="false" MaxLength="2000" Type="varchar" />
 </EntityType>

But when I call a stored procedure, it returns only 1 value of the column

// Stored procedure
public void SelectValue() {
    using (MyConnection ctx = new MyConnection()) {
        foreach (var p in ctx.EntityFramework(2005)) {
            Response.Write(p.Keyword);
        }
    }
}

And this column value is repetitive.

Now how can I get all column value?

Actually I am getting same keyword repetitive.

If I have keyword like Apple, then this keyword is repeating until loop is running.

1 Answer 1

1

You have marked Year as key for the entity. Key must be unique among all records in your defining query otherwise it is not a key. If the key is not unique, EF will do exactly what you got - it will materialize only the first record into entity and use it for all other records as well. EF uses key to identify the entity - if you get two records with the same key value, EF believes that it is the same entity!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.