[英]Entity Framework : How can i translate group by to entity framework statement
[英]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-First
或Model-First
,您应该编辑您的edmx
。 在模型上设置这些属性对您不起作用。
在设计器中打开您的 edmx,然后在该字段的属性中选择您的字段,将Max Length
设置为Max
并将Unicode
为true
。
您也可以从您的 edmx 中删除该实体,然后右键单击并选择Update Model from Database ...
并再次添加该实体,这样如果该字段在数据库中是ntext
,则会在 edmx 中为该字段完成设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.