は、Entity Framework Model First Class Library
のデータを呼び出すClass Library
の機能を呼び出しています。Configuration.ProxyCreationEnabled = false場所はありますか?
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace SADatastore
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class SADatastoreEntities : DbContext
{
public SADatastoreEntities()
: base("name=SADatastoreEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<DB> DBS { get; set; }
....
}
}
が、私はその後、Connections.cs
ファイルIユーザへのを持っている:私は恐ろしい苦しんでい
だから、私のDataStore
クラスライブラリで、私はautogenerated
コンテキストを持っている「自己参照ループが検出されました」ヨーヨーとして...
public partial class SADatastoreEntities
{
public SADatastoreEntities(string connStr)
: base(string.Format(@"metadata=res://*/SAModel.csdl|res://*/SAModel.ssdl|res://*/SAModel.msl;provider=System.Data.SqlClient;provider connection string='{0}'", connStr))
{
// http://stackoverflow.com/questions/12868996/permanently-disable-configuration-proxycreationenabled-in-ef
Configuration.ProxyCreationEnabled = false;
}
}
でcontext
にconnection string
を渡します私は上記のコードで私はを設定しようとしている私は私の問題を解決する必要があります読んでいることがわかります。しかし、それは効果がありません。
public static List<SA_Items> SA_GetAllItemDetails(string connStr, DateTime? lastUpdated, int limit, int offset) {
using (SADatastoreEntities db = new SADatastoreEntities(connStr)) {
if (lastUpdated == null)
lastUpdated = new DateTime(1900, 1, 1);
return db.SA_Items
.Include("SA_Model")
.Include("SA_Model.SA_Manufacturers")
.Where(x => x.LastUpdated > lastUpdated)
.OrderBy(x => x.ItemID)
.Skip(offset)
.Take(limit)
.ToList();
}
}
私はそうのJSONオブジェクトを文字列に変換しようとしていますラインを追加しました:私はここでは、次のコントローラ
public class SA_GetAllItemDetailsController : ApiController
{
[Route("SA_GetAllItemDetails")]
[HttpGet]
public List<SA_Items> Get(DateTime? lastUpdated = null, int limit = 100, int offset = 0)
{
try
{
if (Helpers.Authorise(Request, "WriteVisitors").Authorised)
{
List<SA_Items> result = new List<SA_Items>();
result = SADatastoreEngine.Functions.Item.SA_GetAllItemDetails(
Settings.Default.ConnectionString,
lastUpdated,
limit,
offset
);
// conver the result to a string to have a look at it
string json = JsonConvert.SerializeObject(result, Formatting.Indented);
return result;
}
else
{
throw new HttpResponseException(Helpers.RespondNotAuthorised());
}
}
catch (Exception e)
{
throw new HttpResponseException(Helpers.RespondWithAnError(e));
}
}
}
public class SA_GetItemByItemIdController : ApiController
{
[Route("SA_GetItemByItemId/{id}")]
[HttpGet]
public SA_Items Get(string id)
{
try
{
if (Helpers.Authorise(Request, "WriteVisitors").Authorised)
return SADatastoreEngine.Functions.Item.GetItemByItemId(Settings.Default.ConnectionString, id);
else
{
throw new HttpResponseException(Helpers.RespondNotAuthorised());
}
}
catch (Exception e)
{
throw new HttpResponseException(Helpers.RespondWithAnError(e));
}
}
}
public class SA_CreateItemController : ApiController
{
[Route("SA_CreateItem")]
[HttpPost]
[ValidateViewModel]
public Dictionary<string, string> Post(SA_Items item)
{
try
{
// get the auth details
AuthorisationModel auth = Helpers.Authorise(Request, "WriteVisitors");
if (Helpers.Authorise(Request, "WriteVisitors").Authorised)
{
return SADatastoreEngine.Functions.Item.CreateItem(Settings.Default.ConnectionString, auth.DBSId, item);
}
else
{
throw new HttpResponseException(Helpers.RespondNotAuthorised());
}
}
catch (Exception e)
{
throw new HttpResponseException(Helpers.RespondWithAnError(e));
}
}
}
public class SA_UpdateItemController : ApiController
{
[Route("SA_UpdateItem")]
[HttpPut]
public Dictionary<string, string> Post(SA_Items item)
{
try
{
// get the auth details
AuthorisationModel auth = Helpers.Authorise(Request, "WriteVisitors");
if (auth.Authorised)
{
return SADatastoreEngine.Functions.Item.UpdateItem(Settings.Default.ConnectionString, auth.DBSId, item);
}
else
{
throw new HttpResponseException(Helpers.RespondNotAuthorised());
}
}
catch (Exception e)
{
throw new HttpResponseException(Helpers.RespondWithAnError(e));
}
}
}
がSA_GetAllItemDetails
機能である持っている私のAPIで
私はそれを見ることができます。しかし、これがエラーを投げる場所です。それは間違った場所にありますので、私は設定
Configuration.ProxyCreationEnabled = false;
を感じている
が無視されています。しかし、私はそれがどこにあるべきかを考え出すことはできません。
私が間違ってやっていることを誰にでも見てもらえますか?
JsonSerializerSettings _jsonSettings = new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
// convert the result to a string to have a look at it
string json = JsonConvert.SerializeObject(result, Formatting.Indented, _jsonSettings);
「System.OutOfMemoryExceptionには、」エラー
SADatastoreEngine.Functions.Item.SA_GetAllItemDetailsの内容は何ですか? – Evk
@Evkはそのコードを追加しました...ごめんなさい –
'SA_GetAllItemDetails'はこの問題を抱えませんが、' public SADatastoreEntities():base( "name = SADatastoreEntities") 'を使用すると、間違った動作をします。あなたが 'this(" name = ... "と呼ぶことを意図していたと思う")' –