خرید بک لینک

Vote count: 0

I have a Model which is mapped to the database via EF7. All properties are identical to the mapped columns of the table.

Now I have a Stored Procedure, which retus some Joined Columns but the basis is still the mapped Model.

Here is my model(Entity) which is mapped to Table1 on my database.

public partial class Table1 { public int id { get; set; } public bool Column1{ get; set; } public int Column2 { get; set; } public int Column3 { get; set; } public int Column4 { get; set; } public int Column5 { get; set; } }

My StoredProcedure retus all of these columns and additionally a Column from another table, which contains additional information on this object.

So My StoredProcedure looks like this:

CREATE PROCEDURE Table1_Select
    AS
        BEGIN
            SELECT  Column1,
                    Column2,
                    Column3,
                    Column4,
                    Column5,
                    Table2.JoinedColumn1
            FROM    Table1
            JOIN    Table2 on Table1.ID = Table2.ID_Table1
        END

My Idea was to just add a Property to the Model

public string JoinedColumn1 {get; set;}

This is working for executing the StoredProcedure, but it's not working as soon as I want to get one Entity with

MyContext.Table1.FirstOrDefault(t=>t.id == 1)

this always retus a Server Error 500 in Fiddler whereas the Stored Procedure Execution with "Table1.FromSql("Table1Select")" works fine.

Or do I have to decide whether to use StoredProcedures for my Model OR accessing Entities directly?

Any Best-Practices or solutions for this?

Many thanks in advance. Nicn

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 8 ارديبهشت 1395 ساعت: 15:55

صفحه بندی