如何使用实体框架插入ntext

本文关键字:插入 ntext 框架 实体 何使用 | 更新日期: 2023-09-27 18:20:18

我需要使用实体框架执行这种类型的命令`插入表(列)值(N'

这是我的代码

 public ActionResult PDFGeneration(string format)
 {
        var myFont = Path.Combine(Server.MapPath("~/App_Data/Font/"), "font.ttf");
        Rectangle pgeSize = new Rectangle(595, 792);
        Document pdfDoc = new Document(PageSize.A4, 50, 50, 50, 0f);
        PdfWriter pdfwriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        BaseFont bfR = BaseFont.CreateFont(myFont ,BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        BaseColor clrBlack = new BaseColor(0, 0, 0);
        Font fntHead = new Font(bfR, 12, Font.NORMAL, clrBlack);
        //pdfDoc.Add(new Paragraph("Літера ї є я ь", fntHead));

        using (MedicalDictionaryEntities mde = new MedicalDictionaryEntities())
        {
            mde.Database.Connection.Open();
            var listTUa = from x in mde.TranslationUA select x;
            foreach (TranslationUA tua in listTUa)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append(tua.Word).Append(" - ");
                foreach(TranslationEN ten in tua.TranslationEN)
                {
                    builder.Append(ten.Word).Append(", ");
                }
                pdfDoc.Add(new Paragraph(builder.ToString(),fntHead));
            }
        }
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Generated.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Write(pdfDoc);
        Response.End();
        return View("Index");
    }

我工作,但我得到的是???????,而不是西里尔字母。

我将这些列添加到实体模型中,但对没有帮助

    [MaxLength]
    [Column(TypeName = "ntext")]
    public string Word { get; set; }

我尝试在SQL Server中执行Insert table(column) values (N'текст'),它成功了。

所以我的问题是:如何使用代码和EF执行这种类型的命令?

如何使用实体框架插入ntext

如果使用Database-FirstModel-First,则应编辑edmx。在模型上设置这些属性对您不起作用。

在设计器中打开您的edmx,然后选择您的字段,在字段的属性中,将Max Length设置为Max,并将Unicode设置为true

您也可以从edmx中删除该实体,然后右键单击并选择Update Model from Database ...,然后再次添加该实体,这样,如果数据库中的字段是ntext,则将对edmx的字段进行设置。