将来自存储过程函数的自定义属性映射到实体框架
我正在使用 nop commerce 电子商务开源 1.9,其中他们使用实体框架。
他们有一个存储过程,用于加载所有产品并将该存储过程映射到 sp_ProductLoadAllPaged
函数
现在我更改该存储过程,并在该 sp 的输出中添加一列,即 languages< /代码>。
我还在 Product.cs 类文件中声明了 languages
属性。
但现在,当我使用快速监视时,所有产品的 linguals
列均为空。
我在模型浏览器中更新了数据库中的 .edmx
文件。
现在我检查是否缺少类和存储过程中语言属性的一些映射
,因此请告诉我如何将存储过程的这个新列映射到产品类语言属性。
请参阅下图以获取更多信息
正如您可以检查我进行更改以获取的存储过程最终选择语句该产品的语言
SELECT
p.ProductId,
p.Name,
p.ShortDescription,
p.FullDescription,
p.AdminComment,
p.TemplateId,
p.ShowOnHomePage,
p.MetaKeywords,
p.MetaDescription,
p.MetaTitle,
p.SEName,
p.AllowCustomerReviews,
p.AllowCustomerRatings,
p.RatingSum,
p.TotalRatingVotes,
p.Published,
p.Deleted,
p.CreatedOn,
p.UpdatedOn,
p.AmazonLink,
p.ProductCode,
p.CategoryText,
STUFF((Select ','+ [Name] from Nop_Language where Nop_Language.LanguageId in
(Select Nop_ProductLocalized.LanguageID
from
Nop_ProductLocalized
where
ProductID=p.ProductId
) for xml path('')),1,1,'') as 'languages'
FROM
#PageIndex [pi]
INNER JOIN Nop_Product p with (NOLOCK) on p.ProductID = [pi].ProductID
WHERE
[pi].IndexID > @PageLowerBound AND
[pi].IndexID < @PageUpperBound
ORDER BY
IndexID
I am using nop commerce e-commerce open source 1.9 in which they use the Entity Framework.
They have one stored procedure which loads all the products and map that stored procedure to sp_ProductLoadAllPaged
function
Now I change that stored procedure and in out put of that sp their is one more column which is languages
.
I also declare the languages
property in product.cs class file.
But now as I use quick watch languages
column is null for all products.
I updated the .edmx
file from database in model browser.
Now I check that I am missing some mapping of languages attribute which in class and stored procedure
So please tell me how to map this new column of stored procedure to product class languages properties.
please see the below image for more information
As you can check the stored procedure final select statement where I made changes to get the languages of that product
SELECT
p.ProductId,
p.Name,
p.ShortDescription,
p.FullDescription,
p.AdminComment,
p.TemplateId,
p.ShowOnHomePage,
p.MetaKeywords,
p.MetaDescription,
p.MetaTitle,
p.SEName,
p.AllowCustomerReviews,
p.AllowCustomerRatings,
p.RatingSum,
p.TotalRatingVotes,
p.Published,
p.Deleted,
p.CreatedOn,
p.UpdatedOn,
p.AmazonLink,
p.ProductCode,
p.CategoryText,
STUFF((Select ','+ [Name] from Nop_Language where Nop_Language.LanguageId in
(Select Nop_ProductLocalized.LanguageID
from
Nop_ProductLocalized
where
ProductID=p.ProductId
) for xml path('')),1,1,'') as 'languages'
FROM
#PageIndex [pi]
INNER JOIN Nop_Product p with (NOLOCK) on p.ProductID = [pi].ProductID
WHERE
[pi].IndexID > @PageLowerBound AND
[pi].IndexID < @PageUpperBound
ORDER BY
IndexID
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅仅修改类是不够的。新属性必须在 EDMX 中已知,并且 EDMX 中的模板必须在类中为您生成该属性。
因此,如果
sp_ProductLoadAllPaged
是一个实体,您必须在 EDMX 中手动添加属性并映射它。如果它是复杂类型,则必须在函数导入向导中更新复杂类型。如果您将其作为 XML 打开(在进行手动更改之前将当前版本保存在某处),您还可以直接在 EDMX 中执行这两种方法。It is not enough to modify the class. The new property must be known in EDMX and template from EDMX must generate that property in class for you.
So if
sp_ProductLoadAllPaged
is an entity you must manually add property in EDMX and map it. If it is a complex type you must update the complex type in function import wizard. You can also do both approaches directly in EDMX if you open it as XML (save your current version somewhere prior to doing manual changes).