locked
asp.net web api from a databse object RRS feed

  • Question

  • User-1950594959 posted

    Hi, I am working on exposing a SQL Server database object via get method to third party applications. I am using the below stored procedure.

    create procedure [dbo].[spGetData]
    @code varchar(250) = null
    as

    select

    ,
    [Text]
    from [dbo].

    where (
     = @code or @code is null)

    In the asp.net web api since it was throwing error for no key field for the entity type. I modified the Models file to below and add a field as a complex type.

    public partial class spGetData_Result
    {
    [Key]
    public string Code { get; set; }
    public string Text { get; set; }
    }

    This is the error message I get.

    The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'. The type 'spGetData_Result' is mapped as a complex type. The Set method, DbSet objects, and DbEntityEntry objects can only be used with entity types, not complex types.

    So how would I do it using a database object where the fields are of string type and no key value defined.

    Thanks in advance......

    Friday, June 17, 2016 5:08 PM

Answers