簡體   English   中英

如何使用實體框架插入 ntext?

[英]How can I insert ntext with Entity Framework?

我需要使用實體框架執行這種類型的命令`插入表(列)值(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 執行此類命令?

如果您使用Database-FirstModel-First ,您應該編輯您的edmx 在模型上設置這些屬性對您不起作用。

在設計器中打開您的 edmx,然后在該字段的屬性中選擇您的字段,將Max Length設置為Max並將Unicodetrue

您也可以從您的 edmx 中刪除該實體,然后右鍵單擊並選擇Update Model from Database ...並再次添加該實體,這樣如果該字段在數據庫中是ntext ,則會在 edmx 中為該字段完成設置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM