我们正在使用DB First Entity Framework,其中我们有一个存储过程,它将返回所有列,但只返回一个表。当我尝试映射该存储过程以返回实体类型时,它崩溃说
<pre>
Wom The. Bat
May 2, 2015
Wom The Bat, 91, of city, formerly of Texas, died in the hospital. He was born in city, California. He is survived by two sons. Condolences: somewebsite.com.
Baz Foo Bar<FLAG>
April 30, 2015
Baz Foo Bar, 88, of city, an Internal Revenue Service tax examiner, died at home. She was born in another city. She is survived by three daughters; 5 grandchildren; and 2 great-grandchildren. Services: 10:30 a.m. Private burial.
John Doe<FLAG>
April 17, 2015
John F. Doe, 51, of city, a structural engineer, died in the city. He was born in the Philippines. He is survived by his wife, son, daughter, and two parents. Visitation: 9:30 a.m. Monday. Eulogy: 10:30 a.m. Mass: 11:15 a.m. Burial: 1 p.m.
Jane Smith
May 1, 2015
Jane "Mary" Smith, 64, of city, a storage specialist, died in the hospital. She was born in city, Rhode Island. She is survived by a son; two brothers; four sisters; and her caregiver. Graveside services: 11 a.m. Monday at cemetary. Urn burial to follow. Condolences: somewebsite.com.
</pre>
我知道我可以创建一个复杂的类型来匹配sp返回的内容,或者我可以从sp本身返回一个默认值,但我想知道的是,无论如何,我可以请求ef设置' 0'进入MyTableId,如果存储过程没有返回它?
答案 0 :(得分:1)
http://msdn.microsoft.com/en-US/data/jj691402
引用文章:
注意:EF在使用Translate方法创建实体时不会考虑任何映射。它只会将结果集中的列名与类上的属性名匹配。
您必须将属性标记为[NotMapped],或者通过存储过程返回具有默认值的列。
Select
ColA, ColB, ColC ,
[MyColumnName] = convert(bit , 0) /* this would mimic a false (dotnet) , aka, bit in sql-server */
from
dbo.MyTable
确保在convert语句中有正确的数据类型。