linq clone error

error:

Object graph for type 'Uye.UyeMacAdresi' contains cycles and cannot be serialized if reference tracking is disabled.

solution:

in dbml file change the 'Serialization Mode' to 'Unidirectional'

method overload with single method

private void ShowInfo(string info, bool stayOnPage = true)
{
PopupInfo1.SetFunctionality(stayOnPage);
}

usage:

ShowInfo("Policy not found!");

or

ShowInfo("Policy not found!", false);

t-sql - Retrieving Error Information

-- Create procedure to retrieve error information.
CREATE PROCEDURE usp_GetErrorInfo
AS
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_SEVERITY() AS ErrorSeverity
,ERROR_STATE() AS ErrorState
,ERROR_PROCEDURE() AS ErrorProcedure
,ERROR_LINE() AS ErrorLine
,ERROR_MESSAGE() AS ErrorMessage;
GO

-- Sample:
BEGIN TRY
-- Generate divide-by-zero error.
SELECT 1/0;
END TRY
BEGIN CATCH
-- Execute error retrieval routine.
EXECUTE usp_GetErrorInfo;
END CATCH;

http://msdn.microsoft.com/en-us/library/ms175976.aspx

linq - Row not found or changed

trouble:

var daskTeklif = _context.tblDaskTeklifs.SingleOrDefault(dt => dt.teklif_id == TeklifTkID);
daskTeklif.SirketPoliceNo = policeNo;
_context.SubmitChanges();

throws an exception: System.Data.Linq.ChangeConflictException: Row not found or changed.

solution:

creating a new datacontext:

var context = new DataClassesDataContext();
daskTeklif = context.tblDaskTeklifs.SingleOrDefault(dt => dt.teklif_id == TeklifTkID);
daskTeklif.sirketPoliceNo = policeNo;
context.SubmitChanges();

cycle error on cloning linq object

error: "Object graph for type 'TestLinq.PersonAddress' contains cycles and cannot be serialized if reference tracking is disabled.”

solution: change the 'Serialization Mode' to 'Unidirectional'.

source: http://stackoverflow.com/questions/1432501/clone-linq-object-error-object-graph-for-type-testlinq-personaddress-contains

clone linq object

///



/// Clones any object and returns the new cloned object.
///

/// The type of object.
///
The original object./// The clone of the object.
public static T Clone(T source)
{
var dcs = new DataContractSerializer(typeof(T));
using (var ms = new System.IO.MemoryStream())
{
dcs.WriteObject(ms, source);
ms.Seek(0, System.IO.SeekOrigin.Begin);
return (T)dcs.ReadObject(ms);
}
}


source:http://stackoverflow.com/questions/2178080/linq-to-sql-copy-original-entity-to-new-one-and-save

session killer script

this one line of script is a killer of asp.net session on ie 7, 8, and 9 browsers (maybe ie6, i didn't test it):

$(document).ready(function() {
// for remembering the selected tabs
$("div[id*='tabs']").tabs({ cookie: { expires: 999, name: this.id }, cache: false, collapsible: true });
}

script'i 2 parça halinde yazmak buna neden oluyor.


//        // for remembering the selected tabs
        //        $("div[id*='tabs']").tabs({ cookie: { expires: 999, name: this.id }, cache: false, collapsible: true });

        // fade effect
        $("div[id*='tabs']").tabs({
            fx: {
                opacity: 'toggle',
                duration: 'fast'
            },
            cookie: { expires: 999, name: this.id }, cache: false, collapsible: true
        });

t-sql find object references

select object_name(object_id), OBJECT_DEFINITION(object_id)
from sys.objects
where OBJECT_DEFINITION(object_id) like '%CDS%' and type='P'

örn: ProductId alanının kullanıldığı sp'ler.

streamreader encoding

sorun: doğru encoding verilmezse türkçe karakterler okunamıyor.

çözüm:
StreamReader sr = new StreamReader("ornek.txt", Encoding.GetEncoding("windows-1254"));
textBox1.Text = sr.ReadToEnd();

Value cannot be null. Parameter name: name

add web reference ile web service eklenirken, veya web service çalıştırılırken, dbml'in güncel olmaması nedeniyle bulunamayan nesneler (stored procedure vb.) bu hataya neden olabiliyor.

search this blog (most likely not here)